-3 json objective-c ios
我是iOS新手。我想在iOS中解析这种类型的JSON响应。这是贝宝的回应。我想访问所有数据并制作字典并将其存储以用于其他目的。如何访问所有字段并将其设置为字典?
{
client = {
environment = sandbox;
"paypal_sdk_version" = "2.0.1";
platform = iOS;
"product_name" = "PayPal iOS SDK";
};
response = {
"create_time" = "2014-04-12T05:15:25Z";
id = "PAY-72670124ZX823130UKNEMX3I";
intent = sale;
state = approved;
};
"response_type" = payment;
}
Run Code Online (Sandbox Code Playgroud)
您需要使用以下内容解析JSON: JSONObjectWithData:options:error:
NSData *data = responseData; // Data from HTTP response
NSError *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (!dictionary) {
// An error occured - examine 'error'
}
NSString *responseType = dictionary[@"response_type"]; // Will extract "payment" out of the JSON
NSDictionary *client = dictionary[@"client"];
NSDictionary *response = dictionary[@"response"];
NSString *paypalSDKVerion = client[@"paypal_sdk_version"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
872 次 |
| 最近记录: |