我有一个字符串,然后我需要它作为json,所以我可以解析它并获取键的对象。NSString到字典?或json然后到字典?获取字符串键的对象
例如,我需要一个数组中的ID的所有对象来显示在一个表中。 我该如何处理字符串?
对此提出建议?
这里的字符串:
{
"COMMON": {
"RESULT_CD": "0000",
"RESULT_MSG": "SUCCESS",
"CATEGORY": "computing",
"SVC_ID": "7",
"TARGET": "list(VM)",
"REQUEST_DATE": "201410271741",
"PAGE_NO": 0,
"NUM_PER_PAGE": 0
},
"DATA": {
"VM_LIST": [
{
"@SVC_ID": "7",
"ID": "VMSPE0000000083",
"VM_ALIAS": "CV00900000083",
"VM_OPER_DESC": "Power On",
"MACHIN_STATUS_DESC": "[150748]success:virtual machine power on",
"USVC_DESC": "7/Running, No Change r/hurhurhur, Inc.",
"PURPOSE_NM": "Service_Default",
"VIRT_TYPE_DESC": "Para Virtualization",
"SERVER_STATUS_MSG": "VM running",
"VCPU_CNT": "2",
"MEM_SIZE_MB": "1024",
"VNIC_CNT": "1",
"OS_NAME": "CentOS_6.4_en_64"
},
{
"@SVC_ID": "7",
"ID": "VMSPE0000000093",
"VM_ALIAS": "CV00900000093",
"VM_OPER_DESC": "Reboot",
"MACHIN_STATUS_DESC": "[150749]success:virtual machine reboot",
"USVC_DESC": "7/Running, No Change r/hurhurhur, Inc.",
"PURPOSE_NM": "Service_Default",
"VIRT_TYPE_DESC": "Para Virtualization",
"SERVER_STATUS_MSG": "VM running",
"VCPU_CNT": "1",
"MEM_SIZE_MB": "2048",
"VNIC_CNT": "1",
"OS_NAME": "Gentoo _2011-0 _en_64"
},
{
"@SVC_ID": "7",
"ID": "VMSPE0000000096",
"VM_ALIAS": "CV00900000096",
"VM_OPER_DESC": "Vm Initialization",
"MACHIN_STATUS_DESC": "[163023]success:virtual machine running",
"USVC_DESC": "7/Running, No Change r/hurhurhur, Inc.",
"PURPOSE_NM": "Service_Default",
"VIRT_TYPE_DESC": "Para Virtualization",
"SERVER_STATUS_MSG": "VM running",
"VCPU_CNT": "2",
"MEM_SIZE_MB": "1024",
"VNIC_CNT": "1",
"OS_NAME": "OpenSuse_12.1_en_64"
}
]
}
}
编辑:
下面是我能够给谷歌。
NSDictionary *JSON =
[NSJSONSerialization JSONObjectWithData: [response dataUsingEncoding:NSUTF8StringEncoding]
options: NSJSONReadingMutableContainers
error:nil];
但是,比较字符串NSLog到JSON NSLog!
字符串:
{
"COMMON": {
"RESULT_CD": "0000",
"RESULT_MSG": "SUCCESS",
"CATEGORY": "computing",
"SVC_ID": "7",
"TARGET": "list(VM)",
"REQUEST_DATE": "201410271757",
"PAGE_NO": 0,
"NUM_PER_PAGE": 0
},
"DATA": {
"VM_LIST": [
{
"@SVC_ID": "7",
"ID": "VMSPE0000000083",
"VM_ALIAS": "CV00900000083",
"VM_OPER_DESC": "Power On",
"MACHIN_STATUS_DESC": "[150748]success:virtual machine power on",
"USVC_DESC": "7/Running, No Change r/hurhurhur, Inc.",
"PURPOSE_NM": "Service_Default",
"VIRT_TYPE_DESC": "Para Virtualization",
"SERVER_STATUS_MSG": "VM running",
"VCPU_CNT": "2",
"MEM_SIZE_MB": "1024",
"VNIC_CNT": "1",
"OS_NAME": "CentOS_6.4_en_64"
},
{
"@SVC_ID": "7",
"ID": "VMSPE0000000093",
"VM_ALIAS": "CV00900000093",
"VM_OPER_DESC": "Reboot",
"MACHIN_STATUS_DESC": "[150749]success:virtual machine reboot",
"USVC_DESC": "7/Running, No Change r/hurhurhur, Inc.",
"PURPOSE_NM": "Service_Default",
"VIRT_TYPE_DESC": "Para Virtualization",
"SERVER_STATUS_MSG": "VM running",
"VCPU_CNT": "1",
"MEM_SIZE_MB": "2048",
"VNIC_CNT": "1",
"OS_NAME": "Gentoo _2011-0 _en_64"
},
{
"@SVC_ID": "7",
"ID": "VMSPE0000000096",
"VM_ALIAS": "CV00900000096",
"VM_OPER_DESC": "Vm Initialization",
"MACHIN_STATUS_DESC": "[163023]success:virtual machine running",
"USVC_DESC": "7/Running, No Change r/hurhurhur, Inc.",
"PURPOSE_NM": "Service_Default",
"VIRT_TYPE_DESC": "Para Virtualization",
"SERVER_STATUS_MSG": "VM running",
"VCPU_CNT": "2",
"MEM_SIZE_MB": "1024",
"VNIC_CNT": "1",
"OS_NAME": "OpenSuse_12.1_en_64"
}
]
}
}
JSON:
{
COMMON = {
CATEGORY = computing;
"NUM_PER_PAGE" = 0;
"PAGE_NO" = 0;
"REQUEST_DATE" = 201410271757;
"RESULT_CD" = 0000;
"RESULT_MSG" = SUCCESS;
"SVC_ID" = 7;
TARGET = "list(VM)";
};
DATA = {
"VM_LIST" = (
{
"@SVC_ID" = 7;
ID = VMSPE0000000083;
"MACHIN_STATUS_DESC" = "[150748]success:virtual machine power on";
"MEM_SIZE_MB" = 1024;
"OS_NAME" = "CentOS_6.4_en_64";
"PURPOSE_NM" = "Service_Default";
"SERVER_STATUS_MSG" = "VM running";
"USVC_DESC" = "7/Running, No Change r/hurhurhur, Inc.";
"VCPU_CNT" = 2;
"VIRT_TYPE_DESC" = "Para Virtualization";
"VM_ALIAS" = CV00900000083;
"VM_OPER_DESC" = "Power On";
"VNIC_CNT" = 1;
},
{
"@SVC_ID" = 7;
ID = VMSPE0000000093;
"MACHIN_STATUS_DESC" = "[150749]success:virtual machine reboot";
"MEM_SIZE_MB" = 2048;
"OS_NAME" = "Gentoo _2011-0 _en_64";
"PURPOSE_NM" = "Service_Default";
"SERVER_STATUS_MSG" = "VM running";
"USVC_DESC" = "7/Running, No Change r/hurhurhur, Inc.";
"VCPU_CNT" = 1;
"VIRT_TYPE_DESC" = "Para Virtualization";
"VM_ALIAS" = CV00900000093;
"VM_OPER_DESC" = Reboot;
"VNIC_CNT" = 1;
},
{
"@SVC_ID" = 7;
ID = VMSPE0000000096;
"MACHIN_STATUS_DESC" = "[163023]success:virtual machine running";
"MEM_SIZE_MB" = 1024;
"OS_NAME" = "OpenSuse_12.1_en_64";
"PURPOSE_NM" = "Service_Default";
"SERVER_STATUS_MSG" = "VM running";
"USVC_DESC" = "7/Running, No Change r/hurhurhur, Inc.";
"VCPU_CNT" = 2;
"VIRT_TYPE_DESC" = "Para Virtualization";
"VM_ALIAS" = CV00900000096;
"VM_OPER_DESC" = "Vm Initialization";
"VNIC_CNT" = 1;
}
);
};
}
的JSON缺少的东西!
这是好吗?
你知道任何关于'NSJSONSerialization'吗? – 2014-10-27 08:51:13
...或关于谷歌,对此? – 2014-10-27 08:51:37
请检查编辑,谢谢 – 2014-10-27 09:03:39