我有网络服务:“http://nclex.testshell.net/api/forums/1?type=json”放在“json lint”格式化程序中,但数据不是来自网络服务。但是这个webservice直接放在浏览器中然后数据就会来。这是一个Dot net 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.
请帮助我。在此先感谢。