gpt4 book ai didi

iphone - 获取 NULL 值解析 JSON 字符串

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:07 26 4
gpt4 key购买 nike

我有这个 JSON 数据:

 {
"data":{
"mat_149":{
"id":"149",
"title":"The closing of 40% profit within 9 month",
"teaser":"profit within 9 months only which is equal to 52% annual profit",
"body":" The auction was presented in a very high and commercial lands.\u000d\u000a",
"files":{
"911":{
"fid":"911",
"filename":"22.JPG",
"filepath":"http://mysite/files/22_0.JPG"
}
}
},
"mat_147":{
"id":"147",
"title":"Company launches the city ",
"teaser":"demands for distinguished lands.",
"body":" The area size is quare meters This is evident through projects and many other projects.\u000d\u000a\u000d\u000a",
"files":{
"906":{
"fid":"906",
"filename":"2D7z.jpg",
"filepath":"http://mysite/dlr/files/2D7Z.jpg"
}
}
},
"mat_link":"mysite.com/"
}
}

我正在使用 json 框架解析它:

NSString *response = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding] ;
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:response error:nil];
NSLog(@"Data : %@", [data valueForKey:@"data"] );

我得到 NULL:

[2599:207] Data : (null)

有人可以指出我做错了什么/我该如何解决这个问题?

最佳答案

试试这个

   NSLog(@"Data : %@", [data objectForKey:@"data"] );

更多

  SBJSON *parser = [[[SBJSON alloc] init] autorelease];//should be release

对于他修改过的问题

    for (NSMutableArray *arr in [data objectForKey:@"data"] ) {



for (NSMutableArray *arr1 in [arr objectForKey:@"files"]) {


for (NSMutableArray *arr2 in arr1) {




NSLog(@"fid : %@ \n\n",[arr2 valueForKey:@"fid"]);

NSLog(@"filename : %@ \n\n",[arr2 valueForKey:@"filename"]);

NSLog(@"filepath : %@ \n\n",[arr2 valueForKey:@"filepath"]);


}


}


}

关于iphone - 获取 NULL 值解析 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6716358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com