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发送到配置文件的东西,那将是非常好的!
答案 0 :(得分: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"));
答案 1 :(得分:0)
是的,您必须将JsonObject
转换为String
,然后通过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){
}
答案 2 :(得分:0)
您可以在下面写一行
JSONString url = objectname.getJsonString("url");
然后投入意图