如何解析已经双引号 json数据
例如:JSON Received - “first_name”= Noah;
这是我使用的代码。
//"first_name" = Noah;
NSString *name=[result valueForKeyPath:@"first_name"];
if ([result.grantedPermissions containsObject:@"email"]) {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSString *gender=[result valueForKeyPath:@"gender"];
}
}
}
答案 0 :(得分:1)
当您使用NSDictionary的{ }
方法显示字典(例如,当您执行NSLog时隐式执行)时,数据显示如下:
<key> = <value>
个字符包围。;
,_
分隔对。"
),则会显示为双引号括起来(123
)。"first_name"
是NSString还是NSNumber。因此,通常不需要关心显示的键或值,例如 <head>
<link rel="stylesheet" href="/static/libs/font-awesome4/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="/static/libs/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/script.js"></script>
<link rel="stylesheet" href="/_debug_toolbar/static/css/toolbar.css?0.7082793798424954" type="text/css">
</head>
- 它只是一个普通的NSString。
答案 1 :(得分:1)
使用三重报价
NSString *name=[result valueForKeyPath:@"""first_name"""];
if ([result.grantedPermissions containsObject:@"email"]) {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {NSString *gender=[result valueForKeyPath:@"gender"];
}
}
}