2014-08-28 66 views
0

HI我使用以下网址错误解析数据org.json.JSONException安卓

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

解析JSON和下面是代码

  @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的是

 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રમેશ પારેખ એટલે નખશિખ ગીતોના મોતીઓથી ફાટફાટ 

回答

0

在这里看到你的输出:http://json.parser.online.fr/

其返回JSONArray所以你必须得到像

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); 

月它会为你工作。