[英]Parse json to NSDictionary could not save correct
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[request setHTTPMethod:@"GET"];
NSString *str =[NSString stringWithFormat:@""];
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
NSError *error;
NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *currencyDic = [NSJSONSerialization JSONObjectWithData:received options:NSJSONReadingMutableContainers error:&error];
我想將json保存到currencyDic
,但是某些數據無法保存在關鍵位置
json:
{
"data": [
{
"USD2JPY": 106.544998,
"USD2SGD_ts": 1465039761,
"USD2ITL_ts": 1434960300,
"USD2FRF": 5.7601,
"USD2GBP": 0.688942,
"USD2MOP_ts": 1464990701,
"USD2CHF": 0.975795,
"USD2AUD_ts": 1465039761,
"USD2EUR_ts": 1465039761,
"USD2EUR": 0.879817,
"USD2CNY_ts": 1465039761,
"USD2HKD_ts": 1465039761,
"USD2CAD_ts": 1465039761,
"USD2ITL": 1700.272217,
"USD2CHF_ts": 1465039761,
"USD2DEM": 1.71745,
"USD2DEM_ts": 1434958500,
"USD2GBP_ts": 1465039761,
"USD2JPY_ts": 1465039761,
"USD2HKD": 7.7678,
"USD2FRF_ts": 1434958260,
"USD2CNY": 6.56645,
"DATA_ts": 1465116640,
"USD2AUD": 1.357589,
"USD2MOP": 8.00155,
"USD2CAD": 1.2938,
"USD2SGD": 1.35655
}
],
"status": "ok"
}
而且我使用Xcode監視值
currencyDic __NSDictionaryM * 2 key/value pairs 0x00007fc7ac35c110
[0] (null) (no summary) : (no summary)
[1] (null) (no summary) : @"1 element"
key NSTaggedPointerString * 0xd D\x16F\x17\x06\0\0\xa0
value __NSArrayM * @"1 element" 0x00007fc7ac35c0e0
[0] __NSDictionaryM * 27 key/value pairs 0x00007fc7ac35c0b0
[0] (null) (no summary) : (double)0.975795
key NSTaggedPointerString * 0x0 W5E$3\x84d\xa4
value __NSCFNumber * (double)0.975795 0x00007fc7ac330400
[1] (null) @"USD2JPY_ts" : (long)1465039761
[2] (null) @"USD2FRF_ts" : (long)1434958260
key __NSCFString * @"USD2FRF_ts" \xf0\xbf5\xac\xc7\x7f\0\0
value __NSCFNumber * (long)1434958260 0xb0000005587b9b43
........
所有字符串(例如“ USD2JPY”)都無法解析,只是“沒有摘要”,但是“ USD2SGD_ts”可以保存到NSDictionary中。 我嘗試更改選項( NSJSONReadingMutableContainers
), NSJSONReadingMutableLeaves
, NSJSONReadingAllowFragments
),這是行不通的。
怎么解決?
Xcode使用的-debugDescription
打印對象。 其中進行了一些優化,以防止打印時間過長。 打印為“(無摘要)”的只是類NSTaggedPointerString
字符串。 但是它們是有效的字符串。
您應該為此提交一個錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.