Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONKit parsing json string

Tags:

json

iphone

How to use JSONKit to deserialize a json string into dictionary? I couldn't find any examples.

like image 549
happy_iphone_developer Avatar asked Mar 13 '11 15:03

happy_iphone_developer


People also ask

How do you parse a string of JSON response?

Example - Parsing JSON parse() to convert text into a JavaScript object: const obj = JSON. parse('{"name":"John", "age":30, "city":"New York"}'); Make sure the text is in JSON format, or else you will get a syntax error.

How can I convert JSON to string?

Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);

How do you parse JSON?

parse() JSON parsing is the process of converting a JSON object in text format to a Javascript object that can be used inside a program. In Javascript, the standard way to do this is by using the method JSON. parse() , as the Javascript standard specifies.

What is JSON parsing example?

JSON (JavaScript Object Notation) is a straightforward data exchange format to interchange the server's data, and it is a better alternative for XML. This is because JSON is a lightweight and structured language.


1 Answers

Use the NSString interface that comes with JSONKit. For example:

NSDictionary *deserializedData = [jsonString objectFromJSONString];

You'll either need to know in advance what sort of container you're going to get from the JSON data, or else test the object you get back to figure out its type. (You can use -isKindOfClass: for this.) Most of the time, you already have an expectation of what's in the JSON data, so you know to expect a dictionary or an array, but it's still a good idea to check the class of the object you get back.

like image 91
Caleb Avatar answered Oct 10 '22 18:10

Caleb