简体   繁体   English

将json解析为NSDictionary无法保存正确的

[英]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];

I want save json to currencyDic ,but some data couldn't save at key 我想将json保存到currencyDic ,但是某些数据无法保存在关键位置

json: 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"
}  

and I use Xcode watch value 而且我使用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
        ........

All strings like "USD2JPY" could not parse,just "no summary",but "USD2SGD_ts" can save into NSDictionary. 所有字符串(例如“ USD2JPY”)都无法解析,只是“没有摘要”,但是“ USD2SGD_ts”可以保存到NSDictionary中。 I try to change option( NSJSONReadingMutableContainers ), NSJSONReadingMutableLeaves , NSJSONReadingAllowFragments )It's doesn't work. 我尝试更改选项( NSJSONReadingMutableContainers ), NSJSONReadingMutableLeavesNSJSONReadingAllowFragments ),这是行不通的。
How to fix it?Thanks 怎么解决?

Xcode uses -debugDescription of the to print out objects. Xcode使用的-debugDescription打印对象。 There are some optimizations in it to prevent the print-out of being too long. 其中进行了一些优化,以防止打印时间过长。 What is printed as "(no summary)" are simply strings of the class NSTaggedPointerString . 打印为“(无摘要)”的只是类NSTaggedPointerString字符串。 But they are valid strings. 但是它们是有效的字符串。

You should file a bug for this. 您应该为此提交一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM