我有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在提前。
你在Log.e中获得了什么(“response:”,strResponseReply);'line? –
我得到的回应:零 – rams
也addgetValuefromUrl方法代码因为如果你得到零意味着问题是在getValuefromUrl方法 –