XMLレスポンスをJSONに変換する必要があります。XMLをiOSでJSONに変換する
マイ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のサポートファイルを使用しています
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"
}
私はオンラインで変換しながら、この応答を取得します。このような反応を得る方法。
ありがとうございました。
その何もない、あなたは、XMLから値を解析した後、辞書にデータを変換することができますが、これを行います、なぜ同じことをやってにしながら、最終的には、xmlファイルを解析する必要がありますので、質問は、 2回..? – iphonic
[iPhone SDKを使用してJSONにXML文字列を変換する方法](http://stackoverflow.com/questions/6354159/how-to-convet-xml-string-to-json-using-iphone-sdk) –
ライアンのコードを使って、うまく動作します。 –