3

我想从 Andother 中的一个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"}}
4

3 回答 3

0

You should specify in more detail what you want to achieve and what you have tried. If what you've posted is actually a JSONObject and not a String containing some JSON, you should be able to simply fetch e.g. the OrderDetails object using

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

If what you have is just a string with some JSON, create a JSONObject of it first:

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

Also see:

于 2013-03-05T07:21:45.140 回答
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");
于 2013-03-05T07:11:42.580 回答
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 和 customer Details 相同

于 2013-03-05T07:07:07.157 回答