2

次のコードでは、次の Web サービスを解析していますが、コメント配列を解析すると、[] のような配列ブラケットとは見なされず、括弧 () を想定しているため、この配列は解析しません。自分。

次のコードスナップを見て、助けてください。

{
    "flag?":false,
    "created_at":"2012-04-29T08:20:04Z",
    "title":"test",
    "user":{
        "name":"abc"
    },
    "comments":[
        {
            "comment":"Hi",
            "created_at":"2012-04-26T07:56:09Z",
            "user":{
                "name":"abc"
            }
        },
        {
            "comment":"hello",
            "created_at":"2012-04-27T07:41:29Z",
            "user":{
                "name":"Mahesh"
            }
        },
        {
            "comment":"good",
            "created_at":"2012-05-01T07:03:02Z",
            "user":{
                "name":"admin"
            }
        }
    ],
    "solution":"test",
    "problem":"test"
}

次のようにコード スナップ =: http://pastebin.com/Dg4hjdKA

4

2 に答える 2

1
NSString *urlstring = @"Your URL";
NSURL *url = [NSURL URLWithString:urlstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSError *error;
NSURLResponse *response;
NSData *returnData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *returnString=[[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);

SBJSON *json = [SBJSON new];
NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:[json objectWithString:returnString error:nil]];

NSArray *Response_Array = [[NSArray alloc] initWithArray:[dict valueForKey:@"comments"]];
于 2012-05-07T13:34:14.727 に答える