In this log, I will write a small example of JSON parsing on the client. In the next log, I will write the server code.
1. Make necessary preparations.
Download asihttprequest class library, available on GitHub, https://github.com/pokeb/asi-http-request/
Download JSON-framework, GitHub also has, https://github.com/stig/json-framework/
2. Add the downloaded class library to the xcode project.
3. Add framework
Libz. dylib
Cfnetwork. Framework
Sentestingkit. Framework
Systemconfiguration. Framework
Mobilecoreservices. Framework
4. After completing the above steps, the following is the key.
Nsurl * url = [nsurl urlwithstring: @ "http ://...... (Here is the server URL)/default. aspx "]; asihttprequest * request = [asihttprequest requestwithurl: url]; [Request startsynchronous]; nsstring * response = [Request responsestring]; nslog (@" % @ ", response ); // output here. Check whether the JSON string is correct. nsmutablearray * Data = [Response jsonvalue]; // The JSON string obtained here contains multiple dictionary for (nsdictionary * dictionary in data) // traverses nsmutablearray {nslog (@ "% @, % @", [dictionary objectforkey: @ "Number"], [dictionary objectforkey: @ "name"]);}
5. Finally, the string corresponding to the parsed key value will be output on the console.