Possible Duplicate:
Json Passing in iphone




我是JSON解析的新手。我有一个服务器响应,我如何获取0索引的“设备名称和ID”。

提前致谢

{

    Successfully =

  (

                {

            0 =             {

              DeviceName = Tommy;

                DeviceTypeId = 1;

                EMEI = xxxxxx;

                GId = xxxxx;

                Id = 105;

                Pet = "<null>";

                PetImage = "352022008228784.jpg";

                ProtocolId = xxxx;

                SimNo = xxxxx;
            };

        }
    );
}

最佳答案

NSDictionary *myJsonResponse; // Let's assume that this is the response you provided

NSString *deviceName = [[[myJsonResponse valueForKey:@"Successfully"] objectAtIndex:0] valueForKeyPath:@"0.DeviceName"];

id theId = [[[myJsonResponse valueForKey:@"Successfully"] objectAtIndex:0] valueForKeyPath:@"0.Id"]; // I am using "id" type here since I don't know if this is an NSString or an NSNumber

关于iphone - 解析JSON。我有服务器响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9786604/

10-14 22:41