我需要将 XML 响应转换为 JSON。
我的 XML 响应:
<commands>
<command id="0" name="GetAPPsProducts">
<command_parameters>
<command_parameter id="0" name="APPs_Code">ATAiOS</command_parameter>
</command_parameters>
<command_result>
<apps_products>
<apps_products id="1">
<apps_code>ATAiOS</apps_code>
<apps_product_id>2</apps_product_id>
<brand_id>2</brand_id>
<brand_desc>Generic</brand_desc>
<brand_product_id>2</brand_product_id>
<product_id>001-7</product_id>
<descrizione>MyTravelApp</descrizione>
</apps_products>
</apps_products>
</command_result>
</command>
我正在使用来自该站点的 XMLReader 支持文件:
我正在使用此代码将 XML 转换为 JSON
NSError *parseError = nil;
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:testXMLString error:&parseError];
NSLog(@" %@", xmlDictionary);
我得到这样的 JSON 响应:
commands = {
command = {
"command_parameters" = {
"command_parameter" = {
id = 0;
name = "APPs_Code";
text = "\n \n \n \n ATAiOS";
};
text = "\n ";
};
"command_result" = {
"apps_products" = {
"apps_products" = {
"apps_code" = {
text = "\n \n \n \n ATAiOS";
};
"apps_product_id" = {
text = "\n 2";
};
"brand_desc" = {
text = "\n Generic";
};
"brand_id" = {
text = "\n 2";
};
"brand_product_id" = {
text = "\n 2";
};
descrizione = {
text = "\n MyTravelApp";
};
id = 1;
"product_id" = {
text = "\n 001-7";
};
text = "\n ";
};
text = "\n ";
};
text = "\n ";
};
id = 0;
name = GetAPPsProducts;
text = "\n ";
};
text = "\n ";
};
text = "\n \n";
};
我需要这样的回应:
{
"commands": {
"command": {
"-id": "0",
"-name": "GetAPPsProducts",
"command_parameters": {
"command_parameter": {
"-id": "0",
"-name": "APPs_Code",
"#text": "ATAiOS"
}
},
"command_result": {
"apps_products": {
"apps_products": {
"-id": "1",
"apps_code": "ATAiOS",
"apps_product_id": "2",
"brand_id": "2",
"brand_desc": "Generic",
"brand_product_id": "2",
"product_id": "001-7",
"descrizione": "MyTravelApp"
}
我在在线转换时收到此响应。如何得到这样的回应。
提前致谢。