我有websevice:“http://nclex.testshell.net/api/forums/1?type=json”,它放在“json lint”格式化程序中,但数据不是来自webservice。但是这个web服务直接放在浏览器中然后数据会来。这是一个Dot net webservice.But编程我得到的回答:“零”。这是我的asynchtask类:
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.
请帮助我。谢谢你。
答案 0 :(得分:0)
使用“json lint”无法检查.NET Web服务是否是正确的Json
答案 1 :(得分: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);
}
}