我正在处理iPhone应用程序并从服务器获取响应,我使用JSON Parser解析响应字符串,它返回字典。现在我不知道如何使用数据因为它带有反斜杠,我在控制台上打印数据我发送此相关图像请检查图像给我一个解决方案。我从最近6小时开始研究这个问题。请给我解决方案。!
(
"{\"category_id\":\"1\", \"category_name\":\"BEVERAGES\", \"image_id\":\"6\"}",
"{\"category_id\":\"1\", \"category_name\":\"BEVERAGES\", \"image_id\":\"7\"}",
"{\"category_id\":\"3\", \"category_name\":\"BREAKFAST\", \"image_id\":\"5\"}",
"{\"category_id\":\"3\", \"category_name\":\"BREAKFAST\", \"image_id\":\"6\"}",
"{\"category_id\":\"4\", \"category_name\":\"ALA CARTE\", \"image_id\":\"2\"}
),
(
"{\"subcategory_id\":\"1\",\"category_id\":\"3\", \"subcategory_name\":\"COMBOS\", \"image_id\":\"\"}",
"{\"subcategory_id\":\"2\",\"category_id\":\"3\", \"subcategory_name\":\"OMELETES\", \"image_id\":\"\"}",
"{\"subcategory_id\":\"3\",\"category_id\":\"3\", \"subcategory_name\":\"GRIDDLES\", \"image_id\":\"\"}"
),
答案 0 :(得分:0)
NSError* error = nil;
NSArray* jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (jsonArray == nil) {
NSLog(@"Error getting jsonArray: %@", error);
// Handle error condition
}
NSArray* categoryArray = jsonArray[0];
for (NSString* innerJson in categoryArray) {
NSData* innerJsonData = [innerJson dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* innerDict = [[NSJSONSerialization JSONObjectWithData:innerJsonData options:0 error:&error];
if (innerDict == nil) {
NSLog(@"Error getting innerDict: %@", error);
// Handle error condition
}
NSString* category_id = innerDict[@"category_id"];
// etc
}
// Repeat for subcategoryArray = jsonArray[1]