android 中的 JSONObject 解析?

JSONObject parsing in android?

JSON对象看起来像

{"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 并将其发送到配置文件 activity 以显示,如果你能想出一些东西,我可以发送 JSON反对个人资料那太好了!!

是的,您必须将 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){
}

像这样尝试:

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"));

你可以在下面写

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

然后输入意图