org.json.JSONException: End of input at character

前端 未结 9 1081
南旧
南旧 2020-12-03 18:42

when I try to get json that doesn\'t have object, it works fine. but when I try go get json that has an object it\'s getting error.

Have you got any idea?

         


        
相关标签:
9条回答
  • 2020-12-03 19:04
    carid = new ArrayList<String>();
            carlogo = new ArrayList<String>();
            carname = new ArrayList<String>();
            prize = new ArrayList<String>();
            availibility = new ArrayList<String>();
    
            ListView carlist=(ListView)findViewById(R.id.listcardetails);
            adapter=new CustomAdapter(this, carid, carlogo, carname, prize, availibility);
            carlist.setAdapter(adapter);
    
    0 讨论(0)
  • 2020-12-03 19:06

    It is better to use optJSONObject instead of getJSONObject because it will not through exception.

    0 讨论(0)
  • 2020-12-03 19:12

    Please check PHP File URL in Browser if get the data means you have problem in android side if browser not shows the data it means problem in PHP file.

    0 讨论(0)
  • 2020-12-03 19:16

    Sometimes the probleme is the URL, if your website forces HTTPS, you have to make sure that you are using an HTTPS URL in your APP.

    String url = "https://example.com/adchara1/";

    0 讨论(0)
  • 2020-12-03 19:20

    I'm not seeing you assign anything to result after this String result = ""; in here pastebin.com/mNVGEnD5 and if you trying to get json object with this

    JSONObject jsonObject = new JSONObject(result);
    

    it'll surely return end of input at character 0 because the string result is empty maybe you can try to replace it with some jsonString you can use this as an example :

    {
        "result": "OK",
        "member_id": "32",
        "first_name": "Android",
        "last_name": "JSON",
        "nickname": "HEY",
        "accesskey": "123556332",
        "facebook_id": "0",
        "facebook_token_expire_date": "0000-00-00 00:00:00",
        "facebook_token_expire_date2": "0000000000000",
        "facebook_token_refresh_date": "0000-00-00 00:00:00",
        "facebook_token_key": "null",
        "status_active": 1 
    }
    
    0 讨论(0)
  • 2020-12-03 19:21

    Change

     JSONObject jsonObject = new JSONObject(result);
    

    to

    result=getJSONUrl(url);  //<< get json string from server
    JSONObject jsonObject = new JSONObject(result);
    

    inside doInBackground method of DownloadJSONFileAsync because currently you are not making any post for getting Json data from the server and just trying to parse an empty string to json

    0 讨论(0)
提交回复
热议问题