Nik*_*ris 1 arrays android jsonobject
我需要一些帮助.我还是Android开发人员的新手.
这是数据的示例
strAPI_TERMINAL= "{ 'terminal': { 'id': 2, 'fmt_id': 'fmt0002', 'terminal_type': 'multiple' }}"
Run Code Online (Sandbox Code Playgroud)
我需要将此对象数据解析为JSONArray
在这里我做了什么......
JSONObject jsonObject = new JSONObject(strAPI_TERMINAL);
JSONArray terminal_array = new JSONArray();
JSONArray t_array = terminal_array.put(jsonObject);
Run Code Online (Sandbox Code Playgroud)
当我注销数据时...是的,就像这样解析数组
t_array[{"terminal":{"fmt_id":"fmt0002","id":2,"terminal_type":"multiple"}]
但当我想使用它来获取"终端"数据时...
JSONArray TERMINAL_JSON=new JSONArray(t_array.getJSONObject(i).getString("terminal").toString());
Run Code Online (Sandbox Code Playgroud)
它说:
Error:Value {"id":2,"fmt_id":"fmt0002","terminal_type":"multiple"}
Run Code Online (Sandbox Code Playgroud)
有人请帮帮我???
谢谢你的帮助...
尝试解析JSON如下:
Run Code Online (Sandbox Code Playgroud)JSONObject obj1 = new JSONObject(strAPI_TERMINAL); try { JSONArray result = obj1.getJSONArray("terminal"); for(int i=0;i<=result.length();i++) { String Id=result.getString("fmt_id"); String terminalType=result.getString("terminal_type"); } } catch (JSONException e) { e.printStackTrace(); }
希望这会帮助你.
谢谢