简体   繁体   中英

Error parsing data org.json.JSONException android

HI I am parsing JSON using below URL

http://kathiyawadikhamir.com/json/post.php?postid=100

and Below is the code

            @Override
      protected Void doInBackground(Void... params) {
       // TODO Auto-generated method stub

       try {
        JSONParser jParser = new JSONParser();
        JSONObject json = jParser
          .getJSONFromUrlByGet("http://kathiyawadikhamir.com/json/post.php?postid=100");
        if (json != null) {

         title = json.getString(TAG_POST_TITLE);
         link = json.getString(TAG_POST_POST_LINK);
         imagePath = json.getString(TAG_POST_IMAGE_URL);
         content = json.getString(TAG_POST_CONTENT);


        }
       } catch (Exception e) {
        System.out.println("catch block");
        e.printStackTrace();
       }

       return null;
      }

Logcat is

     08-28 13:24:51.048: W/EGL_emulation(7548): eglSurfaceAttrib not implemented
     08-28 13:24:53.784: W/EGL_emulation(7548): eglSurfaceAttrib not implemented
     08-28 13:24:56.332: I/System.out(7548): id=2651
     08-28 13:24:56.432: W/EGL_emulation(7548): eglSurfaceAttrib not implemented
     08-28 13:24:56.460: W/EGL_emulation(7548): eglSurfaceAttrib not implemented
     08-28 13:24:57.956: E/JSON Parser(7548): Error parsing data org.json.JSONException: Value [{"content":"૨૭-૧૧-૧૯૪૦ થી ૧૭-૦૫-૨૦૦૬ (અમરેલી)\r\n\r\nરમેશ પારેખ એટલે દોમદોમ કવિતાની સાહ્યબીથી રોમરોમ છલકાતો માણસ.\r\nરમેશ પારેખ એટલે નખશિખ ગીતોના મોતીઓથી ફાટફાટ

See your output here : http://json.parser.online.fr/

Its returning JSONArray so you have get like

JSONArray jsonArray = jParser
          .getJSONFromUrlByGet("http://kathiyawadikhamir.com/json/post.php?postid=100");

//Now get Object from Zero position
JSONObject json = jsonArray.getJSONObject(0);

title = json.getString(TAG_POST_TITLE);
link = json.getString(TAG_POST_POST_LINK);
imagePath = json.getString(TAG_POST_IMAGE_URL);
content = json.getString(TAG_POST_CONTENT);

May it will works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM