当前位置: 代码迷 >> Android >> 一个简单的JSON请求,求帮助。该如何处理
  详细解决方案

一个简单的JSON请求,求帮助。该如何处理

热度:115   发布时间:2016-05-01 22:05:34.0
一个简单的JSON请求,求帮助。。。。
Java code
package com.jiepang;import java.io.UnsupportedEncodingException;import org.apache.http.HttpResponse;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.util.EntityUtils;import org.json.JSONException;import org.json.JSONObject;import android.app.Activity;import android.app.AlertDialog;import android.app.AlertDialog.Builder;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class JiepangActivity extends Activity {    /** Called when the activity is first created. */        TextView nr = null;    Button qr = null;        public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);            nr = (TextView)findViewById(R.id.nr);        qr = (Button)findViewById(R.id.queding);        qr.setOnClickListener(new OnClickListener() {                        @Override            public void onClick(View v) {                                  AlertDialog.Builder dlg = new Builder(JiepangActivity.this);                                                                                    try {                       /***************************发送信息*********************************/                       HttpPost request = new HttpPost("http://api.jiepang.com/v1/locations/show");                        JSONObject param = new JSONObject();                         param.put("guid", "成都豪生国际大酒店");                        param.put("source", "100303");                        StringEntity se;                        se = new StringEntity(param.toString());                        request.setEntity(se);              /***************************接收信息*********************************/                        dlg.setTitle("1111").create().show();                        HttpResponse httpResponse = new DefaultHttpClient().execute(request);                         String retSrc = EntityUtils.toString(httpResponse.getEntity());                         JSONObject result = new JSONObject( retSrc);                          String name = (String) result.get("name");                        String city = (String) result.get("city");                        String addr = (String) result.get("name");                        String checkin_users_num = (String) result.get("checkin_users_num");                                                                    nr.setText("地点名称 :"+name+"\n"+"地点所在城市:"+city+"\n"+"地点地址:"+addr+"\n"+"地点总签到人数:"+checkin_users_num);                                       } catch (Exception e) {                        // TODO Auto-generated catch block                        e.printStackTrace();                    }                             }        });                            }         }    



不能接收信息,请帮助 ,不知道那里错了。。。。

------解决方案--------------------
看看logcat日志吧
  相关解决方案