2013-01-19 27 views
0

我有websevice:「http://nclex.testshell.net/api/forums/1?type=json」它放在「 json lint「格式化程序,但數據不是來自webservice。但這個web服務放置在瀏覽器中直接則將數據come.This是點網webservice.But編程我得到的迴應:「零」。這是我的asynchtask類:數據不是來自jsonlint格式器中的webservice,而是來自webservice的數據直接來自webservice

class ListDoback extends AsyncTask<URL, Integer, Long>{  
protected void onPreExecute() 
{ 
try 
{ 
                  pgrDialog=MyProgressDialog.show(ForumsDetailsActivity.this, null,null); 
} 
catch(Exception e){} 
} 
protected Long doInBackground(URL... arg0) 
{ 
         if(!CheckInternetConnection.isOnline(ForumsDetailsActivity.this)) 
{     
pgrDialog.dismiss();      
new AlertDialog.Builder(ForumsDetailsActivity.this).setTitle(DataUrls.dialogtitle) 
          .setMessage(DataUrls.dialogmsg) 
           .setPositiveButton(DataUrls.dialogbutton, new DialogInterface.OnClickListener() 
          {             public void onClick(DialogInterface dialog, int whichButton) { 
finish();  } 
}).show(); 
cancel (true); 
} 
else 
{ 
Log.e("forum id:",DataUrls.strForumId); 

      strResponseReply=UrltoValue.getValuefromUrl(DataUrls.replyforum+DataUrls.strForumId+"type=json"); 
           Log.e("check",DataUrls.replyforum+DataUrls.strForumId+"?type=json"); 
          Log.e("response:",strResponseReply); 

          try { 
           JSONObject jsonObject=new JSONObject(strResponseReply); 
           JSONObject jObject=jsonObject.getJSONObject("data"); 
           jsonArray=jObject.getJSONArray("Reply"); 

           strReplyId=new String[jsonArray.length()]; 
           strForumId=new String[jsonArray.length()]; 
           strUserId=new String[jsonArray.length()]; 
           strUserName=new String[jsonArray.length()]; 
           strUserPicture=new String[jsonArray.length()]; 
           strNickname=new String[jsonArray.length()]; 
           strAgo=new String[jsonArray.length()]; 
           strPostTopic=new String[jsonArray.length()]; 

           for(int i=0;i<jsonArray.length();i++){ 
            strForumId[i]=jsonArray.getJSONObject(i).getString("ForumId"); 
            strUserId[i]=jsonArray.getJSONObject(i).getString("UserId"); 
            strUserName[i]=jsonArray.getJSONObject(i).getString("UserName"); 
            strNickname[i]=jsonArray.getJSONObject(i).getString("NickName"); 
            strAgo[i]=jsonArray.getJSONObject(i).getString("Ago"); 
            strUserPicture[i]=jsonArray.getJSONObject(i).getString("UserPicture"); 
            strPostTopic[i]=jsonArray.getJSONObject(i).getString("posttopic"); 
            strReplyId[i]=jsonArray.getJSONObject(i).getString("ReplyId"); 

            Log.e("Nick name:",strNickname[i]); 
            Log.e("post topic:",strPostTopic[i]); 
           } 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         }     
        return null; 
       } 
       protected void onProgressUpdate(Integer... progress) 
       { 

       } 
       protected void onPostExecute(Long result) 
       { 
        Log.e("postexecute","onpostexecute"); 
        if(strResponseReply.equals("zero")||jsonArray.length()==0) 
        { 
         Toast.makeText(ForumsDetailsActivity.this, "No forums found", Toast.LENGTH_SHORT).show(); 
        } 
        try 
        { 

         lvPostReply.setAdapter(new ForumsReplyList(ForumsDetailsActivity.this,R.layout.forumreplyitem,strNickname,strPostTopic,strUserPicture,strAgo)); 
        } 
        catch(Exception e) 
        { 
         pgrDialog.dismiss(); 
        } 
        pgrDialog.dismiss(); 
        Log.e("hi","hi"); 
       } 
      } //closing BarPicsDoback process. 

請幫助me.Thanks在提前。

+0

你在Log.e中獲得了什麼(「response:」,strResponseReply);'line? –

+0

我得到的迴應:零 – rams

+0

也addgetValuefromUrl方法代碼因爲如果你得到零意味着問題是在getValuefromUrl方法 –

回答

0

使用此代碼在異步類 ,你會得到響應

try 
{ 
    response = httpclient.execute(httpget); 
    Log.e("Response", "Status:[" + response.getStatusLine().toString() + "]"); 
    Log.e("check",DataUrls.replyforum+DataUrls.strForumId+"?type=application/json"); 
    HttpEntity entity = response.getEntity(); 

    if (entity != null) 
    {            
     InputStream instream = entity.getContent(); 
     strResponseReply = RestClient.convertStreamToString(instream); 
     Log.i("Result", "Result of converstion: [" + strResponseReply + "]"); 
     instream.close(); 
     return result; 
    } 
} 
catch (ClientProtocolException e) 
{ 
    Log.e("REST", "There was a protocol based error", e); 
} 
catch (IOException e) 
{ 
    Log.e("REST", "There was an IO Stream related error", e); 
}    
} 
0

您不能檢查.NET Web服務是否是正確的JSON或不使用「JSON皮棉」