How can i get Json Data if its having in particular Name - angularjs

Here im having data Like
""{\"resultStatus\":\"success\",\"message\":\"AUTH-040010: Successfully logout user\",\"language\":\"en\",\"region\":\"us\",\"securityToken\":\"C29F32A5-CF46-4CE8-B1DF-4FBC207ABA19|13|1550120060454\",\"userName\":\"John\",\"organisationId\":1,\"isSearch\":false,\"productId\":1,\"productKey\":\"fAyhhy455Hh4d52c\",\"menuKey\":\"LOG\",\"pageDto\":{\"selectedPage\":1,\"totalCount\":0,\"recodsPerPage\":25},\"menuMasterDtoList\":{},\"validated\":true}Redirectdata=https://192.168.10.19:8089/iauth/access/login?productId=1&productKey=f8cc80d…a24d52c&redirectUrl=http://172.16.1.135:458/Enquiry/openenquiries&Message= Success&MessageType=1""
in this Url How can i get Redirectdata Url
JSON.stringify(d.data) By using this i convert that string in Json
But
JSON.stringify(d.data.Redirectdata)
This is Giving me undefind
Please help me how can i get Redirectdata Url

It because Redirectdata is not a JSON key its outside of JSON object

Related

Problem in fetch of a json server in react

VM543:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
I have problem at fetch of json server that i made alone .The server is correct
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
You are trying to parse json from your response (string). something like JSON.parse('<!doctype html...')
Your server is not returning an application/json data

Store and fetch customObject array in sessionStorage in angular 2

I am storing PublicationdtoService[] custom object array in a session storage
_publicationList: PublicationdtoService[] = [];
sessionStorage.setItem('sessionPublicationList',JSON.stringify(this._publicationList));
and fetching it back from the object
this._publicationList =<PublicationdtoService[]> (JSON.parse(sessionStorage.getItem('sessionPublicationList')));
Console.log(this._publicationList);
But i am getting the response in Object[] form and not PublicationdtoService[] form. What do I do?
response in console is
But what I am expecting is:
Please Help

Cannot access Google Geocoding API response object

my first message :)
well, i am trying to write a weather Spa with angular.
as part of the model , i need to grab the location Lat and Lon so im using google geocoding api.
after using $resource.get i am successfully getting the object from google but cant access it.
here is my code :
weatherApp.controller('forecastController'['$scope','location','$resource',function($scope,location,$resource){
$scope.toGoogle = location.toGoogle;
$scope.resource = $resource('http://maps.googleapis.com/maps/api/geocode/json?');
$scope.georesult = $scope.resource.get({address:$scope.toGoogle,Key:"somekey"})
console.log(angular.fromJson($scope.georesult));
}]);
$scope.toGoogle is just a var holding the address which needs to be translated into x and y
the thing is - i am getting a response with the object i was expected, but when i am trying to access it with:
console.log(angular.fromJson($scope.georesult.results[0].geometry.location.lat));
I am getting "TypeError: Cannot read property '0' of undefined"
(Please note that i have already transformed the Json into regular object with Angular.fromJson);
Any suggestions ? thanks in advance.

Cloud Endpoints not accepting JSON array

I want to build my endpoint, which accept JSON array of below format:
[
{
"test":"Math",
"result":"Pass"
},
{
"test":"Science",
"result":"FirstClass"
}
]
It will be a POST call with the above JSON to my endpoint.
I tried it with servlet too but did not get the required result, and also tried to with list and inserting in a new class and posting to that class. Thanks in advance.
Is that an accurate representation of the JSON object which is being sent over? Because one does not simply send a a POST request with a JSON object of their param object to a cloud endpoint. See here for a thorough guide to Endpoint API interaction from a javascript perspective - notice how the client library exposes an object "gapi" through which calls are made. If you're sending this JSON from an iOS or Android app, there are similar client libraries which can be generated for you by a cloud endpoints build tool.
After much frustration, I resorted to reading the docs more carefully. In that quest, I found an important note in the doc:
https://cloud.google.com/endpoints/docs/frameworks/java/parameter-and-return-types
"Any type except a parameter or injected type is considered an entity type. ... Entity types cannot be annotated with #Named"
With all examples showing named parameters, I was stumped as the docs don't explain further, but then found a solution. It ends up that if you do not have named parameters, everything is just passed in as a LinkedHashMap. Usually, you can do any work you need to with just that data structure, but if you HAVE to have it in JSON, you can convert it. Here are some examples:
#ApiMethod(name = "endpointIterfaceName.createItems", httpMethod = "post", path = "test/items")
public WhateverReturnType createItems(LinkedHashMap<String, Object> itemsMap) {
// Do Stuff with map values
return whateverReturnValue;
}
With this, you need to be sure that you post your data with the Content-Type of json (i.e. Content-Type:application/json; charset=UTF-8). So, for example, when testing, with a jquery ajax call you would need to set dataType to "json" or with Postman, you would select "Raw" then JSON (application/json).
If you really want to convert this to a JSON object in Java because for whatever reason you can not use a hash map, you can do the following in your method:
// Use gson library to convert the map to a string
Gson gson = new Gson();
String mapAsJsonString = gson.toJson(itemsMap);
// create a JSON object from the new string representation
JSONObject obj = new JSONObject(mapAsJsonString);
As a side note, if this is passed as Content-Type:text then the whole body will be in the map as the first key of the map. You could do some inadvisable things here and just get that key and avoid converting the map to a string and then to a json object, but, like I said, that is inadvisable. :)

Restangular data sent is being splitted

Restangular.one('suppliers', 'me').getList('websites').then(
(data) ->
$scope.websites = data
$scope.websites.patch()
)
I'm just trying this for a quick test.
So the api call on /suppliers/me/websites returns an array but when I try to patch from the Restangular object it sends the data splitted as you can see below.
[{"0":"h","1":"t","2":"t","3":"p","4":":","5":"/","6":"/","7":"w","8":"w","9":"w","10":".","11":"p","12":"f","13":"c","14":"o","15":"n","16":"c","17":"e","18":"p","19":"t","20":".","21":"c","22":"o","23":"m"}]
I'm new to Angular & Restangular , what am I missing ?
Edit : To be clear, I insta patch for the test but normally I modify the websites array by adding / removing.
It looks as if you're returning a string from your service, whereas a valid JSON response is expected by Restangular.
For example:
[{"website": "http://www.example.com"}, {"website": "http://www.domain.com"}]
EDIT: I just noticed that in your question, you say your service returns an array. Double-check what it does return and make sure that it is valid JSON.
EDIT 2: It seems that Restangular expects not only valid JSON, but also JSON formatted as my code sample above is (ie. [{"key": "value"}] and not ["value"].

Resources