Help parsing a nested JSON object

前端 未结 3 1190
别那么骄傲
别那么骄傲 2021-01-06 17:01

I have the following JSON:

{
    \"meta\": {
        \"code\": 200
    }, 
    \"response\": {
        \"deals\": [
            {
                   


        
3条回答
  •  醉梦人生
    2021-01-06 17:45

    From the JSON you provided, locations is an array (that's what the square brackets mean), so the values that are returned from valueForKey: are contained in NSArray instances (hence the parentheses).

    You could use objectAtIndex: before the last call to valueForKey: to obtain just the value you're looking for.

    By the way, you can also use valueForKeyPath: to simplify accessing nested values, for example

    [deal valueForKeyPath:@"business.name"];
    

提交回复
热议问题