private void loginMethod() {
// TODO Auto-generated method stub
FinalHttp http = new FinalHttp();
http.addHeader("Accept", "application/json");
AjaxParams params = new AjaxParams();
params.put("member_id", "8");// 传参数
http.get("http://api.mangxiaoquan.com/v1/my-shops",
new AjaxCallBack<String>() {
@Override
public void onSuccess(String t) {
// TODO Auto-generated method stub
super.onSuccess(t);
SystemOut.println("" + t);
}
@Override
public void onFailure(Throwable t, int errorNo,
String strMsg) {
// TODO Auto-generated method stub
// 加载失败的时候回调
super.onFailure(t, errorNo, strMsg);
SystemOut.println("" + t.toString() + "" + errorNo + ""
+ strMsg);
}
});
}
/*
* JSON
*/
@SuppressWarnings("unused")
private MyShopBean parser(String json) {
SystemOut.println("--->" + json);
try {
JSONTokener jsonParser = new JSONTokener(json);
JSONObject object = (JSONObject) jsonParser.nextValue();
if (object.getString("success").equals("true")) {
MyShopBean bean = new MyShopBean();
JSONObject data = object.getJSONObject("data");
bean.setId(data.getInt("id"));
bean.setName(data.getString("name"));
bean.setTruename(data.getString("truename"));
bean.setAvatar(data.getString("avatar"));
bean.setSex(data.getString("sex"));
bean.setBirthday(data.getString("birthday"));
bean.setEmail(data.getString("email"));
bean.setEmail_bind(data.getString("email_bind"));
bean.setMobile(data.getString("mobile"));
bean.setSnsvisitnum(data.getInt("snsvisitnum"));
bean.setAreaid(data.getInt("areaid"));
bean.setCityid(data.getInt("cityid"));
bean.setProvinceid(data.getInt("provinceid"));
bean.setAreainfo(data.getString("areainfo"));
bean.setPrivacy(data.getString("privacy"));
bean.setQuicklink(data.getString("quicklink"));
bean.setExppoints(data.getInt("exppoints"));
bean.setInviter_id(data.getInt("inviter_id"));
bean.set_links(data.getString("_links"));
SystemOut.println("======>" + bean.toString());
return bean;
} else {
return null;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
求大神,我json解析出来,为什么打印的没有数据啊,我要做的就是解析出来之后和之前的数据做对比就可以了
找个json序列化框架吧,序列化成对象,不要操作键值对啦
现在已经解决,谢谢
你的MyShopBean 的Tostring重写了吗?
重写了
把loginMethod()单独摘出来,get里面加上params参数