Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中解析多行json_Android_Json - Fatal编程技术网

在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

我想从我的服务器上获取一个json文件,并在我的android应用程序中显示它

现在,只要在日志控制台中显示就可以了

我可以得到整个json文件,比如:

[{"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());