Parse json array android

后端 未结 3 1667
渐次进展
渐次进展 2020-12-06 12:59

Hi i\'m trying to parse json array from this url. The json array looks like this.

    [
   {
      \"id\":1,
      \"introtext\":\"\\u041b\\u0438\\u043c\\u04         


        
3条回答
  •  情深已故
    2020-12-06 13:55

    you will need to make two changes in your current code according to string u have posted here for parsing as Json :

    First : change the return type of getJSONfromURL method to JSONArray and return JSONArray from it instead of JSONObject For example :

    public JSONArray getJSONfromURL(String url){
        String str_response="response from server";
    
        // convert response to JSONArray
       JSONArray json_Array=new JSONArray(str_response);
    
       return json_Array; //<< retun jsonArray
    }
    

    Second : change your code as for getting value from JsonArray :

    try {
        JSONfunctions j=new JSONfunctions();
        JSONArray jArray = j.getJSONfromURL(url);
        Log.i("log_tag", jArray.toString()); 
    
         for(int i=0;i

提交回复
热议问题