如何从一个JSONObject获取值到另一个JSONObject

时间:2013-03-05 07:02:57

标签: android json getjson

我想从另一个JSONObject中的一个JSONObject检索数据 任何人都可以告诉我如何回顾他们

我的JSONObject就像这样

{"udetail":{"ID":238597,"Reference":"AGT-ALIWF_TEST","Provider":"TAL","DropDate":"2012-12-29T13:06:00","abc":"South","def":"2013-01-06T13:06:00","ghi":"North"},"jkl":{"Title":"Mr","FirstName":"LastName_TEST","LastName":"FirstName_TEST LastName_TEST"},"mydetail":{"my":"Model_TESTMake_TEST","hi":"Colour_TEST","tget":"A123 XYZ"}}

3 个答案:

答案 0 :(得分:0)

 String s= "{
    "OrderDetails": {
        "ID": 238597,
        "Reference": "AGT-    ALIWF_TEST",
        "Provider": "TAL",
        "DropDate": "2012-12-    29T13:06:00",
        "DropTerminal": "South",
        "ReturnDate": "2013-01-    06T13:06:00",
        "ReturnTerminal": "North"
    },
    "CustomerDetails": {
        "Title": "Mr",
        "FirstName": "LastName_TEST",
        "LastName": "FirstName_TEST     LastName_TEST"
    },
    "CarDetails": {
        "Make": "Model_TESTMake_TEST",
        "Colour": "Colour_TEST",
        "Registration": "A123 XYZ"
    }
}";

试试这个

JSONObject obj=new JSONObject(s);
String orderDetails=obj.getString("OrderDetails");
JSONObject orderjson=new JSONObject(orderDetails);
String Reference=orderjson.getString("Reference");

CarDetails和客户详细信息相同

答案 1 :(得分:0)

试试这个, 要获取订单详细信息,

  JsonObject jobj = new JsonObject(Response);
  String str = jobj.getJSONObject("OrderDetails").getString("ID");

客户详细信息,例如

  String str1 = jobj.getJSONObject("CustomerDetails").getString("Title");

汽车详情

    String str2 = jobj.getJSONObject("CarDetails").getString("Make");

答案 2 :(得分:0)

您应该更详细地指定您想要实现的目标以及您尝试过的内容。如果您发布的内容实际上是JSONObject,而不是包含某些JSON的String,那么您应该能够简单地获取,例如使用

OrderDetails对象
JSONObject details = <Your JSONObject>.getJSONObject("OrderDetails");

如果您拥有的只是带有一些JSON的字符串,请首先创建JSONObject

JSONObject jo = new JSONObject("{"OrderDetails":{"ID":238 ... }}
JSONObject details = <Your JSONObject>.getJSONObject("OrderDetails");

另见: