我试图将NSData转移到NSARRAY或NSDICTIONARY,但NJSONSERIALIZATION正在给我错误1.我已成功多次使用该方法但我不知道为什么在这种特殊情况下无效。
NSMutableURLRequest *request = [WebMethod GetMenuForRestaurant:restaurantid];
NSHTTPURLResponse *response = nil;
NSData *responseData;
NSError *error = nil;
for (int c = 0; c<5; c++) {
//make the request
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
//some hardcode
if (responseData!=nil)
c = 10;
}
if (responseData==nil)
return nil;
NSDictionary* jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
这是我的json:
{"Sections":[{"sectionname":"Main","Products": [{"ProductName":"hamburguer","Price":250.0},{"ProductName":"pasta","Price":300.0},{"ProductName":"pizza","Price":350.0}]},{"sectionname":"desserts","Products":[{"ProductName":"brownie","Price":200.0},{"ProductName":"helado","Price":150.0}]},{"sectionname":"entries","Products":[{"ProductName":"chips","Price":125.0},{"ProductName":"salad","Price":100.0},{"ProductName":"weed","Price":1000.0}]}]}
尝试去实现它,json序列化给了我这个错误:
(<invalid>) [0] = <error: expected ']'
error: 1 errors parsing expression
>