[英]How to convert a string to a JSON and then extract required values from the JSON object?
[英]Extract the values from the json object to the purpose of intent
根據我顯示的代碼示例,responseJson返回FirstName的值。 我想從responseJson中獲取該值,因為我想將其傳遞給下一個活動。 任何幫助將不勝感激。
@Override
protected void onPostExecute(JSONObject result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
String myResJson;
try {
myResJson = responseJson.getString("Status");
String test = myResJson;
if (test.equals("200")) {
Intent intent = new Intent(contxt, ActivityMenu.class);
intent.putExtra("FirstName", firstname);
contxt.startActivity(intent);
} else {
Toast.makeText(contxt,
"Login Error, invalid Email or Password", Toast.LENGTH_SHORT)
.show();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
這是我的responseJson值{"LastName":"A","UserID":"1","Status":"200","FirstName":"P"}
更改
intent.putExtra("FirstName", firstname);
至
intent.putExtra("FirstName", responseJson.getString("FirstName"));
要么
firstname=responseJson.getString("FirstName");
if(firstname!=null)
intent.putExtra("FirstName", firstname);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.