After trying a lot sorry for asking such a trivial question.
Given below screenshot consist of a data that I have successfully received from the server.
I would like to know how to traverse through the data since whenever I try to cast it to something and try a foreach it gives an error.
The actual data sent from the server is a List() type.
I want to know how to cast it to same type and use it here.
I tried casting but it says unexpected token here.
Any help is appreciated.
JSON.parse return type depends on the String you try to parse. See the doc :
Parses json and build the corresponding parsed JSON value.
Parsed JSON values are of the types num, String, bool, Null, Lists of parsed JSON values or Maps from String to parsed JSON values.
From your screenshot, it seems that the return value is a List. You can do something like the following to use it (did you notice the typo in your commented code - .fore) :
final parsedList = JSON.parse(e.data)/*.fore*/;
parsedList.forEach((x){
query('#idData').appendText(x[0]);
query('#idData').appendText(x[1]);
query('#idData').appendText(x[2]);
query('#idData').appendText(x[3]);
});
Related
I got a Rest Assured Response object. While trying to convert from Response object to JSON. The conversation happen successfully but JSON order is mismatch. It would be great if some one assist on this.
Conversion:
JSONObject jobj = new JSONObject(restAssuredResponse.getBody());
Basically, JSON is an unordered set of key value pairs. Which, for any JSON object the order of key/value pairs shouldn't be considered.
The JSON Object should be considered equal even if the order is not the same.
I'm trying to return JSON, to map to a model, however I can't figure out why my method is returning an object literal and not JSON.
I threw together a Fiddle that shows the current format I am receiving data.
Controller method
public JsonResult GetDeferredAccountDetailsByAccount(int id)
{
var details = _deferredAccountDetailsService.GetDeferredAccountDetailsByAccount(id);
return Json(details, JsonRequestBehavior.AllowGet);
}
This returns :
..And in the browser :
In the Fiddle I linked, simply wrapping the object literal in [] allows Knockout to interpret the object just fine, but without it fails.
Is there something I am doing incorrectly or a reason why I'm not receiving JSON? Do I need to return an ICollection or something for it to be interpreted as JSON?
I looked around but couldn't really find anything.
You expects an Array, but you are returning a literal object at the controller. And you are biding a collection using knockout, but accounts It's a literal. That's why everything works when you put [] at the JSON.
You should just push every property from the JSON to an Array instead of _map, or fix the _map function to bind property to an Array!
I know how to parse json object from NSString using NSData and NSDictionary, but I didn't find how to parse multiple json object if I get message like this:
{
"msg_type" : "fist_json",
"field" : "param"
}
{ "second_json_field": [
{
"name_picture": "0.png",
"data_picture":"something"
},
{
"data_values": "something"
} ]
}
{
"third_msg" : "hello"
}
It's not valid JSON, so you can't parse it. A JSON document is either a single array, or a single object (dictionary). Three objects are not valid JSON. You could put square brackets around everything, put commas in the right places, and parse it, getting an array back. Finding the places for the commas without writing a full-blown JSON parser is tricky.
If this is what the server gave you, ask the server people to fix their broken server. If your code for some reason combined three JSON messages into one, then don't do that.
I'm guessing this is not possible in one go. Your provided example text might look like JSON, but it isn't (valid).
I think the service that serves you this response should be 'fixed'.
Can any one suggest me a way to parse string to json.String variable is holding the json data (exact json data).I want to directly return that string to my kendo grid whic take only json data.Is there a way to directly parse the string to json.
Thanks in advance
Take a look at this library, I believe that will help.
Json.NET http://james.newtonking.com/json/help/index.html
I have a problem where I am unable to de-serialise a Json string to an object in cases where the object already has a Json string in it.
Ex:
Class A {
int a;
String jsonRpresenationOfSomeObject;
// other stuff
}
I am unable to de-serialise an object of the above Class A. I get an exception for the field "jsonRpresenationOfSomeObject"
Custom de-serialiser is not an option for my use case. Am looking for something generic.
Also found no luck with the Gson library.
Would appreciate any help on this.
There is no issue in serializing and deserializing in JSON for the above mentioned scenario of yours.
I have tried and found that the JSON is able to deserialize your class properly.
i think their might be problem with Access-Specifier of your class.
If you still face the problem, then prvide us the sample source.