-1

JSON を解析したいのですが、問題は、json オブジェクトが<string>タグ内にあることです。そこから JSON オブジェクトを取得するにはどうすればよいですか?

<string>
    { "SubListList" : {
        "SubList" : [ 
            { 
                "Description" : null,
                "Items" : "6",
                "Name" : "ANAESTHETICS",
                "PPLID" : "4",
                "SubListID" : "87",
                "poSubListItemList" : "clsSubListItemList"
            },
            { 
                "Description" : null,
                "Items" : "6",
                "Name" : "Berris",
                "PPLID" : "4",
                "SubListID" : "93",
                "poSubListItemList" : "clsSubListItemList"
            },
            { 
                "Description" : null,
                "Items" : "18",
                "Name" : "Dentsply",
                "PPLID" : "4",
                "SubListID" : "92",
                "poSubListItemList" : "clsSubListItemList"
            },
            { 
                "Description" : null,
                "Items" : "2",
                "Name" : "INFECTION CONTROL",
                "PPLID" : "4",
                "SubListID" : "88",
                "poSubListItemList" : "clsSubListItemList"
            },
            { 
                "Description" : null,
                "Items" : "3",
                "Name" : "LABORATORY PRODUCTS",
                "PPLID" : "4",
                "SubListID" : "89",
                "poSubListItemList" : "clsSubListItemList"
            },
            { 
                "Description" : null,
                "Items" : "1",
                "Name" : "SURGICAL SUNDRIES",
                "PPLID" : "4",
                "SubListID" : "90",
                "poSubListItemList" : "clsSubListItemList"
            },
            { 
                "Description" : null,
                "Items" : "6",
                "Name" : "X-RAY PRODUCTS",
                "PPLID" : "4",
                "SubListID" : "91",
                "poSubListItemList" : "clsSubListItemList"
            }
        ] } 
    }
</string>
4

2 に答える 2

0

応答を文字列に読み取り、<string>andを削除するだけです</string>

ここに小さなスニペットがあります:

String response = response_from_URL
response = response.replaceAll("<string>", "");
response = response.replaceAll("</string>", "");

LogCat で文字列を確認するにresponseは、上記のスニペットの下に次のコードを追加します。

Log.d("json", response);

そこで、タグがなくなっているかどうかを確認できます。なくなっている場合は、responseJSON として解析できます。

幸運を祈ります^^

于 2013-05-28T07:35:32.087 に答える
0

を使用Regexして文字列を取得するかSAX、xml ファイルを解析してから、new JSONObject(String)JSON を解析するために使用できます。

于 2013-05-28T06:29:39.743 に答える