我的webserice回复面临问题。字典键是自动排序的,我想要它们
实际的网络服务响应是: -
[data] => Array
(
[18] => How it works
[22] => Benefits
[23] => Win Free Airtime
[7] => What can I Report?
[10] => Our Goal
[16] => Disclaimer
[8] => FAQ
[13] => Terms & Conditions
[11] => Contact Us
[14] => Feedback / suggestion
)
并且不幸地通过自动排序显示在下面
data = {
10 = "Our Goal";
11 = "Contact Us";
13 = "Terms & Conditions";
14 = "Feedback / suggestion";
16 = Disclaimer;
18 = "How it works";
22 = Benefits;
23 = "Win Free Airtime";
7 = "What can I Report?";
8 = FAQ;
};
我被卡住了:(下面是我的代码
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
[spinner stopAnimating];
if ([data length] > 0 && error == nil)
{
//NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary * Dict = [NSDictionary dictionary];
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *decryptedStr = [[NSData alloc] initWithBase64EncodedString:newStr options:0];
NSDictionary * Dict = [NSJSONSerialization JSONObjectWithData:decryptedStr options:kNilOptions error:nil];
答案 0 :(得分:1)
没有办法做到这一点,因为结果不是数组而是没有订单的字典。
您必须编写自己的JSON解析器并使用除NSDictionary
之外的其他内容来保留订单。
最好的方法是使用数组更改JSON输出:
{
"data": [
{
"key": 10,
"value": "Our Goal"
},
{
"key": 11,
"value": "Contact Us"
},
{
"key": 13,
"value": "Terms & Conditions"
},
{
"key": 14,
"value": "Feedback / suggestion"
},
{
"key": 16,
"value": "Disclaimer"
},
{
"key": 18,
"value": "How it works"
},
{
"key": 22,
"value": "Benefits"
},
{
"key": 23,
"value": "Win Free Airtime"
},
{
"key": 7,
"value": "What can I Report?"
},
{
"key": 8,
"value": "FAQ"
}
]
}