[Solved] Parsing JSON in Swfit 3.0 Cast NSArray to NSDictionary Error

You can use this : Since the data in items is array of dictionaries and link is not in internal array it is main dictionary so you can easily get this by passing link in as key. let link = “http://www.flickr.com/services/feeds/photos_public.gne?tags=swimming&format=json&nojsoncallback=1” let urlString = link let url = URL(string: urlString) URLSession.shared.dataTask(with:url!) { (data, response, error) … Read more

[Solved] How to get values from JSON Array which doesn’t follow “key” : “value” standard / JSON with no Key?

It’s pretty much the compressed format of JSONArray, I’ve seen it few times, some systems use it to lower the amount of data that gets transferred. You can try something like this (edit how you need it, as this is only a basic concept): // Let us assume your JSON is loaded in jsonString variable … Read more

[Solved] While decoding json from webservice, it shows an error: Could not cast value of type ‘__NSArrayM’ (0x10b84bdb0) to ‘NSDictionary’ (0x10b84c288)

Try this var desriptionArray = [String]() for dataValues in responseObject[“result”] as! [[String: AnyObject]] { let name = dataValues [“description”] as! String desriptionArray .append(name) } OR for (index , element) in (responseObject[“result”] as! [Any]).enumerated() { let nameDict = element as! [String : AnyObject] let strDecription = nameDict[“description”] as! String desriptionArray .insert(strDecription, at: index) } solved While … Read more

[Solved] Any suggestions to deserialize this json with Gson? [closed]

Convert the Json string to Hashmap like below using Google’s Gson, then you can interate through the hashmap String jsonString = “Your JSON string”; HashMap<String, JsonObject> map = new Gson().fromJson(jsonString, new TypeToken<HashMap<String, JsonObject>>(){}.getType()); 2 solved Any suggestions to deserialize this json with Gson? [closed]

[Solved] How to parse JSON values using Swift 4?

Your code cannot work. According to the given JSON the root object is an array [[String: Any]] and there is no key result at all. let json = “”” [{“id”:1,”class”:”A”,”Place”:{“city”:”sando”,”state”:”CA”}},{“id”:1,”class”:”B”,”Place”:{“city”:”jambs”,”state”:”KA”}}] “”” let data = Data(json.utf8) do { if let json = try JSONSerialization.jsonObject(with: data) as? [[String: Any]] { for item in json { if let … Read more

[Solved] Android: Access all nested JSON objects dynamically [duplicate]

Thank you DroiDev and MohamedMohaideenAH. Finally i got the solution private void parseJson(JSONObject jsonObject){ try { for(int i = 0; i < jsonObject.length(); i++){ if(jsonObject.get(jsonObject.names().getString(i)) instanceof JSONObject){ Log.e(“===Start===”, “===Start===”); Log.e(“objectName”, jsonObject.names().getString(i)); JSONObject singleObj = new JSONObject(jsonObject.get(jsonObject.names().getString(i)).toString()); Iterator<String> keys= singleObj.keys(); while (keys.hasNext()){ String keyValue = keys.next(); String valueString = singleObj.getString(keyValue); if(!isJSONObjectOrString(valueString)) Log.e(keyValue, valueString); } Log.e(“===End===”, “===End===”); … Read more

[Solved] JsonArray convert to java code [duplicate]

For above json you must have this classes below: Example.java package com.example; import javax.annotation.Generated; import com.google.gson.annotations.Expose; public class Example { @Expose private To to; public To getTo() { return to; } public void setTo(To to) { this.to = to; } } To.java package com.example; import java.util.ArrayList; import java.util.List; import javax.annotation.Generated; import com.google.gson.annotations.Expose; public class To … Read more

[Solved] I have a JSON file attached below and i want to print it in the console, currently i am using xcode 4.4 [closed]

Assuming you have a file in bundle (as it wasnt clear from the question), you can read the file with following code: NSString * path = [[NSBundle mainBundle] pathForResource:@”YOU_FILE_NAME” ofType:@”txt”]; NSString *jsonString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; then print it to console using: NSLog(@”%@”,jsonString); 4 solved I have a JSON file attached below and i … Read more