ios - NSJSONSerialization data in a different format -
I submit the data to where I currently am using Parse.com as a backend to your application, I am
The data is a list of video game consoles. I was able to make an output about it, but instead of JSON data, the output is a big NSMutableArray
This is my viewDidLoad:.
- (zero) viewDidLoad {[Super Viewedload]; NSURL * url = [NSURL URLWithString: @ "https://api.parse.com/1/classes/Consoles"]; NSMutableURL request * request = [NSMutableURL request request withURL: url]; [Request URL: url]; [Set http system: @ "gET"]; [Request Set Value: @ "APPLICATION_ID" HTTP header field: @ "X-parse-application-id"]; [Request Set Value: @ "REST_API_KEY" for HTTP headerfile: @ "X-Pars-Rest-API-Key"]; NSError * error; ID listOfConsoles = [NSJSONSerialization JSONObjectWithData: [NSURLConnection sendSynchronousRequest: Request ReturningResponse zero error: Zero] Options: NSJSONReadingMutableContainers error: & amp; Error]; NSLog (@ "list:% @", list of console); } Output:
list: {result = ({created created = "2013-03-21T07: 26: 04.149Z"; name = playstation ; objectId = vloIK0MZIA; updatedAt = "2013-03-21T07: 26: 04.149Z";} {createdAt = "2013-03-21T07: 26: 34.209Z", name = Wii; objectId = RIRpgbznlq; updatedAt = "2013- 03-21T07: 26: 34.209Z ";} {createdAt =" 2013-03-21T07: 26: 39.391Z ", name = Xbox; objectId = xBNgHtJbrV; updatedAt =" 2013-03-21T07: 26: 39.391 Z "; }); } I should have the output:
{"results": [{"objectId": "vloIK0MZIA", "updatedAt": "2013-03 -21T07: 26: 04.149Z "," createdAt ":" 2013-03-21T07: 26: 04.149Z "," name ":" PlayStation "}, {" objectId ":" RIRpgbznlq "," updatedAt ":" 2013 -03-21T07: 26: 34.209Z "," createdAt ":" 2013-03-21T07: 26: 34.209Z "," name ":" Wii "}, {" objectId ":" xBNgHtJbrV "" UpdatedAt ":" 2013-03-21T07: 26: 39.391Z "," Created ":" 2013-03-21 Tate: 26: 39.391C "," Name ":" Xbox "}]} < P> By the way Why is it that when I have a different NSDT in the code: NSData * JSONData = [NSURLConnectionSynchronousRequest: Returning Request Spans zero error: zero]; and NSJSONSerialization Change in Me: id listOfConsoles = [NSJSONSerialization JSONObjectWithData: JSONData options: NSJSONReadingMutableContainers error: & amp ; Error]; The output will be:
list: {Arro R = unauthorized; }
The first list is with a NSDictionary The key, which is called "result", in which NSArray is the NSDictionaries . The second list is the same thing ..
1.0 Edit: To make it clear, the second output is JSON , Fine? Just as that, just check and validate yourself. The first one is output JSON which is inside NSObject Of course, there are some differences ...
Comments
Post a Comment