我是 JSON 输出的新手,我正在使用 Gson 解析器来解析输出。
我只想要输出中的汽车名称和卡车代码,当我解析时,我得到带有引号的汽车名称作为输出,我用字符串替换删除引号,我是否正确解析了这些值?
JsonElement jelement = new JsonParser().parse(json);
JsonObject carobject= jelement.getAsJsonObject();
carobject= carobject.getAsJsonObject("Car");
String car = carobject.get("name").toString();
out.println("Car Name:"+car);
JSON输出:
{
"messages": [
"For a complete list use showall=true to display 'intersection' element in the Mask"
],
"Mask": {
"NJS": "120950170151015",
"section": [
{
"NJS": "120950170151015"
},
{
"NJS": "120950170151016"
},
{
"NJS": "120950170151019"
}
]
},
"Car": {
"NJS": "12095",
"name": "Audi"
},
"Truck": {
"NJS": "12",
"code": "TL",
"name": "TLTRUCK"
},
"status": "OK",
"executionTime": "13"
}