Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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 @覆盖 受保护的Void doInBackground(Void…参数){ //创建一个数组 arraylist=新的arraylist(); //从给定的URL地址检索JSON对象 jsonobject=JSONfunctions .getJSONfromURL(“http://demo.cogzideltemplates.com/client/sedio/feed/home_feed?user_id=5&start=1"); 试一试{ //在JSON中找到数组名称 jsonarray=jsonobject.getJSONArray(“世界人口”); for(int i=0;i_Android_Json_Parsing - Fatal编程技术网

在android中解析无顶级标签的JSON @覆盖 受保护的Void doInBackground(Void…参数){ //创建一个数组 arraylist=新的arraylist(); //从给定的URL地址检索JSON对象 jsonobject=JSONfunctions .getJSONfromURL(“http://demo.cogzideltemplates.com/client/sedio/feed/home_feed?user_id=5&start=1"); 试一试{ //在JSON中找到数组名称 jsonarray=jsonobject.getJSONArray(“世界人口”); for(int i=0;i

在android中解析无顶级标签的JSON @覆盖 受保护的Void doInBackground(Void…参数){ //创建一个数组 arraylist=新的arraylist(); //从给定的URL地址检索JSON对象 jsonobject=JSONfunctions .getJSONfromURL(“http://demo.cogzideltemplates.com/client/sedio/feed/home_feed?user_id=5&start=1"); 试一试{ //在JSON中找到数组名称 jsonarray=jsonobject.getJSONArray(“世界人口”); for(int i=0;i,android,json,parsing,Android,Json,Parsing,这是我的代码,但这不适用于我,因为我的 json没有顶级元素我如何运行它 给我举个例子是这样的: @Override protected Void doInBackground(Void... params) { // Create an array arraylist = new ArrayList<HashMap<String, String>>(); // Retrieve JS

这是我的代码,但这不适用于我,因为我的 json没有顶级元素我如何运行它


给我举个例子

是这样的:

@Override
        protected Void doInBackground(Void... params) {
            // Create an array
            arraylist = new ArrayList<HashMap<String, String>>();
            // Retrieve JSON Objects from the given URL address
            jsonobject = JSONfunctions
                    .getJSONfromURL("http://demo.cogzideltemplates.com/client/sedio/feed/home_feed?user_id=5&start=1");
            try {
                // Locate the array name in JSON
                jsonarray = jsonobject.getJSONArray("worldpopulation");

                for (int i = 0; i < jsonarray.length(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    jsonobject = jsonarray.getJSONObject(i);
                    // Retrive JSON Objects
                    map.put("rank", jsonobject.getString("rank"));
                    map.put("country", jsonobject.getString("country"));
                    map.put("population", jsonobject.getString("population"));
                    map.put("flag", jsonobject.getString("flag"));
                    // Set the JSON Objects into the array
                    arraylist.add(map);
                }
            } catch (JSONException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }
String s=“[{”text\”:“疼痛强度”、“问题编号”:1、““id\”:1、{”text\:“个人护理(洗漱、穿衣等)”、““问题编号”:2、““id\”:2、“{”text\”:“提起”、“问题编号”:3、““id\”、“{”text\:“行走”、“问题编号”:4、{,{\'text\':\'siting\',\'question\'u number\':5,\'id\':5}];
试一试{
JSONArray数组=新的JSONArray;

对于(int i=0,l=array.length();i您只需将其作为JsonArraycan u tel获取在本例中如何使用url问题是关于解析JSON的,您必须从url下载字符串,或从资源获取字符串,等等
    String s ="[{    \"text\": \"Pain Intensity\",     \"question_number\": 1,     \"id\": 1}, {    \"text\": \"Personal Care (washing, dressing, etc.)\",     \"question_number\": 2,     \"id\": 2}, {    \"text\": \"Lifting\",     \"question_number\": 3,     \"id\": 3}, {    \"text\": \"Walking\",     \"question_number\": 4,     \"id\": 4}, {    \"text\": \"Sitting\",     \"question_number\": 5,     \"id\": 5}]";


    try {
        JSONArray array = new JSONArray(s);

        for (int i =0 ,l=array.length() ; i<l; i++) {
            JSONObject jsonObject = array.getJSONObject(i);
            String text = jsonObject.getString("text");
            int qNumber = jsonObject.getInt("question_number");
            int id = jsonObject.getInt("id");
           //handle here the variables ...
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }