Android 解析数组中的json数据数组

Android 解析数组中的json数据数组,android,json,web-services,parsing,Android,Json,Web Services,Parsing,如何像这种格式解析json数组? 解析时出现此错误:无法转换为json对象。请参见此处 { "TABLE":[ { "ROW":[ { "COL":[ { "DATA":"< OutBoundSMS PhoneId='3' PhoneNo='1111111111' MessageText='OutBound SMS A

如何像这种格式解析json数组? 解析时出现此错误:无法转换为json对象。

请参见此处

   {
   "TABLE":[
      {
         "ROW":[
            {
               "COL":[
                  {
                     "DATA":"< OutBoundSMS PhoneId='3' PhoneNo='1111111111' MessageText='OutBound SMS Application Test' />"
                  }
               ]
            }
         ]
      }
   ]
}
这里是一个很好的例子

   {
   "TABLE":[
      {
         "ROW":[
            {
               "COL":[
                  {
                     "DATA":"< OutBoundSMS PhoneId='3' PhoneNo='1111111111' MessageText='OutBound SMS Application Test' />"
                  }
               ]
            }
         ]
      }
   ]
}

下面是一个很好的示例,将当前Json字符串解析为:

String jsonStr = '{"menu": {' + 
        '"id": "file",' + 
        '"value": "File",' + 
        '"popup": {' + 
          '"menuitem": [' + 
            '{"value": "New", "onclick": "CreateNewDoc()"},' + 
            '{"value": "Open", "onclick": "OpenDoc()"},' + 
            '{"value": "Close", "onclick": "CloseDoc()"}' + 
          ']' + 
        '}' + 
      '}}'; 

将当前Json字符串解析为:

String jsonStr = '{"menu": {' + 
        '"id": "file",' + 
        '"value": "File",' + 
        '"popup": {' + 
          '"menuitem": [' + 
            '{"value": "New", "onclick": "CreateNewDoc()"},' + 
            '{"value": "Open", "onclick": "OpenDoc()"},' + 
            '{"value": "Close", "onclick": "CloseDoc()"}' + 
          ']' + 
        '}' + 
      '}}'; 
其工作原理是在数组中解析json数据数组

处理

其工作原理是在数组中解析json数据数组

处理


但是它的数组可以再次搜索NagarjunaReddy.p但是它的数组可以再次搜索NagarjunaReddy.Pits可以工作,但是我无法从OutBoundSMS标签中获取hashmap中的数据,所以请suggest@NitinGupta:您在数据中获取的字符串不是xml或其他json字符串。因此,您需要在“的基础上拆分它,并使用replace删除不需要的字符。这很有效,但我无法从OutBoundSMS标记中获取hashmap中的数据,所以请suggest@NitinGupta:您在数据中获取的字符串不是xml或其他json字符串。因此,您需要在“并使用替换删除build.gradle filecompile”com.android中不需要的字符和依赖项”的基础上对其进行拆分。volley:volley:1.0.0“在build.gradle filecompile'com.android中添加依赖项。volley:volley:1.0.0”
import android.app.Dialog;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {

    private Dialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        callApiArrayInsideArray();
    }


    private void callApiArrayInsideArray() {
        JSONObject jsonObject = new JSONObject();

        // TODO Send parameter using this in volley apis
        /*try {
            jsonObject.put("UserId", "abc");
        } catch (JSONException e) {
            e.printStackTrace();
        }*/
//        String url = Constants.GetData;
        String url = "http://maps.googleapis.com/maps/api/directions/json?origin=28.4759618,77.3140897&destination=28.3936072,77.3172154&sensor=false&mode=driving&alternatives=true";

        mDialog = ProgressDialog.show(MainActivity.this, "", "Please wait", true);
        mDialog.setCancelable(false);


        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url,
                jsonObject, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.i("tag", "Volley response: " + response.toString());
                if (mDialog != null) {
                    mDialog.dismiss();
                }
                // TODO when Success Response  then set parse data in list view
                parseResponse(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (mDialog != null) {
                    mDialog.dismiss();
                }
                Log.i("tag", "Volley error: " + error.getMessage());
            }
        });
        Volley.newRequestQueue(this).add(jsonObjectRequest);
    }

    private void parseResponse(JSONObject response) {
        try {
            JSONArray jsonArray = response.getJSONArray("routes");

            Log.e("MainActivity", "jsonArray --> " + jsonArray.toString(2));
            if (jsonArray != null)
            {
                for (int i = 0; i < jsonArray.length(); i++)
                {
                    JSONObject jsonnew = jsonArray.getJSONObject(i);
                    JSONArray jsonarrayROW = jsonnew.getJSONArray("legs");

                    for (int j = 0; j < jsonarrayROW.length(); j++)
                    {
                        JSONObject jsonnewtwo = jsonarrayROW.getJSONObject(j);
                        JSONArray jsonarrayCOL = jsonnewtwo.getJSONArray("steps");

                        for (int k = 0; k < jsonarrayCOL.length(); k++)
                        {
                            JSONObject jsonnewthree = jsonarrayCOL.getJSONObject(k);
                            String str_data = jsonnewthree.getString("html_instructions");
                            Log.e("Keshav", "html_instructions -> " + str_data);
                        }
                    }
                    Log.e("Keshav", "GeoEvent List->");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}