在Android中解析多行json
我想从我的服务器上获取一个json文件,并在我的android应用程序中显示它 现在,只要在日志控制台中显示就可以了 我可以得到整个json文件,比如:在Android中解析多行json,android,json,Android,Json,我想从我的服务器上获取一个json文件,并在我的android应用程序中显示它 现在,只要在日志控制台中显示就可以了 我可以得到整个json文件,比如: [{"name":"john", "surname":"connor"}, {"name":"sarah", "surname":"connor"}] 但是,在android中,如果我尝试使用这样的字符串,它会失败,因为[] 如果我尝试: JSONObject json=new JSONObject(result); //result has
[{"name":"john", "surname":"connor"}, {"name":"sarah", "surname":"connor"}]
但是,在android中,如果我尝试使用这样的字符串,它会失败,因为[]
如果我尝试:
JSONObject json=new JSONObject(result); //result has the previous string
Log.i("TEST", json.toString());
我必须删除[and]才能继续进行nn日志,我只有json的第一个入口
如果我离开,它什么也不做。在第一行之前停车
完整的示例代码如下所示 更换这个
JSONObject json=new JSONObject(result); //result has the previous string
Log.i("TEST", json.toString());
与
您的原始字符串是json数组而不是json对象。@Biribu-请参阅-它在一页上完全解释了您需要了解的关于json格式的所有内容。谢谢。我马上就来,谢谢。现在我有了所有的数据。
JSONArray json=new JSONArray(result); //result has the previous string
Log.i("TEST", json.toString());