我的任务是解析一些通过在XML WADL上运行XML到JSON转换工具而创建的JSON。我能够将响应中返回的数据解析为JSON,并且我能够从数据中获取顶级NSDictionary。我可以从字典中获取一个数组,并从数组中获取一个NSDictionary(它包含键值,但就是这样),这就像我可以去的那样深。我在过去做过解析但是这个特殊的JSON格式我运气不好?这是我正在使用的代码..
// Decode the data
NSError *parseError = nil;
NSData *jsonData = [request responseData];
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&parseError];
if (parseError) {
NSLog(@"Error: %@", [parseError localizedDescription]);
// other stuff..
return;
}
NSLog(@"JSON=: %@", responseDict.description);
NSArray *messageBoxResponse = [responseDict objectForKey:@"messageBoxResponse"];
NSLog(@"messageBoxResponse=: %@", messageBoxResponse);
NSUInteger count = messageBoxResponse.count;
for (NSDictionary* messages in messageBoxResponse) {
NSLog(@"Messages=: %@", messages.description);
NSArray *message = [messages objectForKey:@"message"];
// get SIGABRT
count = message.count;
// If I comment out above line and introduce this I get SIGABRT also
for (NSDictionary* something in message) {
NSLog(@"Somthing=: %@", something.description);
}
这是我试图解析的JSON .. IP已被更改:):
{
messageBoxResponse = {
messages = {
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages";
rel = self;
};
message = (
{
flags = {
answered = 0;
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<4F3131A3.6040204@sc-msg1-msg.sc.sc>/flags";
rel = self;
};
taggedForDeletion = 0;
unread = 0;
};
from = "Suren.1@sc-msg1-msg.sc.sc";
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<4F3131A3.6040204@sc-msg1-msg.sc.sc>";
rel = self;
};
parts = {
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<4F3131A3.6040204@sc-msg1-msg.sc.sc>/parts";
rel = self;
};
part = {
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<4F3131A3.6040204@sc-msg1-msg.sc.sc>/parts/0";
rel = self;
};
mimeType = "TEXT/PLAIN";
name = "text.txt";
size = 564;
};
};
receivedDate = 1328624061000;
sentDate = 1328624035000;
subject = test;
},
{
flags = {
answered = 0;
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>/flags";
rel = self;
};
taggedForDeletion = 0;
unread = 0;
};
from = "Suren.1@sc-msg1-msg.sc.sc";
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>";
rel = self;
};
parts = {
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>/parts";
rel = self;
};
part = (
{
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>/parts/0";
rel = self;
};
mimeType = "TEXT/PLAIN";
name = "text.txt";
size = 6;
},
{
content = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>/parts/1/2c3a3400620f218d5378607260dc2749.wav";
rel = content;
};
duration = 3;
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>/parts/1";
rel = self;
};
mimeType = "AUDIO/WAV";
name = "Audio_Recording_S000551_002.wav";
size = 31190;
},
{
link = {
href = "http://1.1.1.1:80/services/messageboxes/63358/messages/<24346739.35.1328562602976.JavaMail.mango@sc-msg1-msg.sc.sc>/parts/2";
rel = self;
};
mimeType = "APPLICATION/MS-TNEF";
name = "winmail.dat";
size = 656;
}
);
};
receivedDate = 1328562604000;
sentDate = 1328562596000;
subject = "Voice Message from Suren 1 (63357)";
}
);
};
};
}
答案 0 :(得分:0)
因为json无效。看起来应该更像这样:
{
"messages": {
"link": {
"href": "http: //1.1.1.1: 80/services/messageboxes/63358/messages",
"rel": "self"
}
}
}
'='需要':'有分号不应该在那里。