【发布时间】:2010-12-01 20:15:02
【问题描述】:
我试图从这个字典中提取两个值,但是我得到的值在它们周围有“()”。任何想法是什么原因造成的?
这是服务器输出:
{"Rows":[{"userid":"1","location":"beach"}]}
JSON 后的字典:
{
Rows = (
{
location = beach;
userid = 1;
}
);
}
这就是我得到的:
location : (
beach
)
user Id : (
1
)
用户 ID 和位置键值都有“()”。这是代码。非常感谢。
NSString *serverOutput= [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
if(serverOutput > 1){
SBJSON *jsonFF = [[SBJSON new] autorelease];
NSError *error3 = nil;
NSDictionary *useridDict= [jsonFF objectWithString:serverOutput error:&error3];
NSLog(@"useridDict: %@",useridDict);
idreturn = [[useridDict valueForKey:@"Rows"] valueForKey:@"userid"];
locationreturn = [[useridDict valueForKey:@"Rows"] valueForKey:@"location"];
NSLog(@" user Id : %@", idreturn);
NSLog(@" location : %@", locationreturn);
【问题讨论】:
-
locationreturn 是如何声明的?是 NSArray 吗?
-
idreturn 和 locationreturns 是 NSStrings。谢谢
-
它似乎将值决定为数组,虽然我不知道为什么。
-
@Wevah 谢谢,我将返回设置为数组,现在正在使用:NSString * idreturnst = [idreturn objectAtIndex:0];获得价值。
标签: iphone nsstring nsarray nsdictionary