前台获取后台定义的jsonArray中的值(按id获取个人用户信息)

2025-04-08 08:55:54
推荐回答(2个)
回答1:

//returnValue从后台返回的数据
JSONArray jsonArray = new JSONArray(returnValue);
for (int i = 0; i < jsonArray.length(); i++) {
    JSONObject resultJsonObject = jsonArray.getJSONObject(i);
    //该用户所有数据包括微信、qq等
    UserBean userBean = new UserBean();
    userBean.setName(resultJsonObject .getString("userid"));
    userBean.setIdcard(resultJsonObject .getString("nickName"));
    userBean.setFace(resultJsonObject .getString("icon"));
    ····
    ··
    //list.add(userBean)
 }
 
 你点击跳转的时候获取你点击的数据传送到下个界面
 Intent intent = new Intent(Main.this, Sec.class);
 Bundle bundle = new Bundle();
 bundle.putSerializable("UserBean ", userBean);
 intent.putExtras(bundle);
 startActivity(intent);
 下个界面接收
 Intent intent = this.getIntent();
 UserBean userBean= (UserBean ) intent.getSerializableExtra("UserBean ");

回答2:

$.ajax({
url: '....',
type: 'GET',
data: {'...': '...'},
dataType: 'json',
success: function (response) {
var result = response;
if (typeof response == 'string') {
//一般是返回json串
result = JSON.parse(response);
}
console.dir(result);
},
error: function (e) {
//...
}
});