小编Pet*_*ter的帖子

使用objective-c从json中检索值

我目前正在尝试使用json和objective-c但是有点困难.以下是返回的json

{
    sethostname =     (
    {
        msgs = "Updating Apache configuration\nUpdating cPanel license...Done. Update succeeded.\nBuilding global cache for cpanel...Done";
        status = 1;
        statusmsg = "Hostname Changed to: a.host.name.com";
        warns =             (
        );
    });
}
Run Code Online (Sandbox Code Playgroud)

我能够检查响应是否会返回并且密钥是sethostname但是无论我尝试什么,我都无法获得例如status或statusmsg的值.任何人都可以指出我在正确的位置.以下是我用来检查是否返回sethostname的基本代码.

NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&myError];
NSLog([res description]);
NSArray *arr;
arr = [res allKeys];
if ([arr containsObject:@"sethostname"])
{
    NSLog(@"worked");
}
Run Code Online (Sandbox Code Playgroud)

api json objective-c nsdictionary cpanel

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

api ×1

cpanel ×1

json ×1

nsdictionary ×1

objective-c ×1