Putting JSON into an Array

前端 未结 3 1980
花落未央
花落未央 2020-12-12 05:59

I\'m a noob when it comes to requests and JSON. Inside my app I send to the server and get back stuff so I can use it of course. I tried looking up different things but none

3条回答
  •  再見小時候
    2020-12-12 06:12

    if your JSON format like {"mainKey":[{},{},...]}

     NSError* error;
        NSDictionary* json = [NSJSONSerialization 
            JSONObjectWithData:responseData //1
             options:kNilOptions 
            error:&error];
    
        NSArray* dataArray = [json objectForKey:@"mainKey"]; //2
    

    else your JSON format like [{},{},...]

    NSError* error;
        NSArray* dataArray = [NSJSONSerialization 
            JSONObjectWithData:responseData //1
            options:kNilOptions 
            error:&error];
    

    I think your format is case 2: [] Array of Object {}

    Tutorial: http://www.raywenderlich.com/5492/working-with-json-in-ios-5

    JSON:http://www.json.org

提交回复
热议问题