0

json の変換に助けが必要です。

これが私のコードです:

try {
    JSONObject mainJson22 = new JSONObject(reply);

    JSONArray jsonArray22 = mainJson22.getJSONArray("UserListByBusinessAreaContextResult");
    Log.i("mainjson234","" +  jsonArray22);

    for (int i2 = 0; i2 < jsonArray22.length(); i2++) {
        JSONObject objJson22 = jsonArray22.getJSONObject(i2);   
//      JSONArray innerJsonArray = jsonArray.getJSONArray(i);
//      JSONObject objJson = innerJsonArray.getJSONObject(0);

        int id22 = objJson22.getInt("UserID");
        String username22 =objJson22.getString("Username"); 
        String name = objJson22.getString("Name");

        reply =  {"UserListByBusinessAreaContextResult":"{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}"}

およびログ:

org.json.JSONException: タイプ java.lang.String の UserListByBusinessAreaContextResult の値 {"tableData":[{"UserID":30,"Username":"Teste","Name":"Teste"}]} は変換できませんJSONArray へ

ログには、エラーが次の行にあることが示されています。

mainJson22.getJSONArray("UserListByBusinessAreaContextResult");
4

1 に答える 1

1

UserListByBusinessAreaContextResult

is not an Array. It's a JSONObject.

tableData is your JSONArray. So you must have :

try { 
JSONObject mainJson22 = new JSONObject(reply);
JSONArray jsonResult = mainJson22.getJSONObject("UserListByBusinessAreaContextResult");
JSONArray jsonArray22 = jsonResult.getJSONArray("tableData");
Log.i("mainjson234","" +  jsonArray22);

for (int i2 = 0; i2 < jsonArray22.length(); i2++) {

   JSONObject objJson22 = jsonArray22.getJSONObject(i2);
...
于 2013-06-05T01:02:14.533 に答える