1

JSONObject 看起来像

{"result":
     {
        "id":"1",
        "name":"ankur",
        "email":"ankur@gmail.com",
        "address":"bblock",
        "designation":"devloper",
        "department":"development",
        "balanceleave":"5"
     }
}

我的解析代码看起来像

Intent intent = new Intent(Login.this, Profile.class);
intent.putExtra("id", response.getString("id"));
intent.putExtra("name", response.getString("name"));
intent.putExtra("email", response.getString("email"));
intent.putExtra("address", response.getString("address"));
intent.putExtra("designation", response.getString("designation"));
intent.putExtra("department", response.getString("department"));
intent.putExtra("balanceleave", response.getString("balanceleave"));

startActivity(intent);

你能帮我吗,实际上我正在解析 JSON 并将其发送到配置文件活动以显示,如果你能想出一些我可以将 JSONObject 发送到配置文件的东西,那就太好了!

4

3 回答 3

2

试试这样:

JSONObject response=new JSONObject("your response string");
JSONObject result=response.getJSONObject("result");
String id=result.getString("id");
String name=result.getString("name"));
String email=result.getString("email"));
String address=result..getString("address"));
String designation=result.getString("designation"));
String department=result.getString("department"));
String balanceleave=result.getString("balanceleave"));
于 2017-07-08T08:05:01.127 回答
0

是的,您必须转换JsonObjectString然后发送Bundle到配置文件屏幕。像下面

Intent intent = new Intent(Login.this, Profile.class);
intent.putExtra("JSON_OBJECT", response.toString());


                                startActivity(intent);

得到那个

Intent i = getIntent();
String json = i.getStringExtra("JSON_OBJECT");
try{
JsonObject json = new JsonObject(json);
}catch(Exception e){
}
于 2017-07-08T07:59:46.617 回答
0

你可以在下面写

JSONString url = objectname.getJsonString("url");

然后投入意图

于 2017-07-08T08:09:27.097 回答