JSON
springを使用してjacksonテクノロジーと同様にいくつかのpojoをマップしてWebサービスを作成しようとしていますが、リストをマップすると次のようJSON
な不正な形式が作成されるため、問題があります。JSON
["idLine":"a61dcedb-4a6b-4f8f-bbdd-32cc51e861b2",
"name":"line1",
"code":"pru1"
]
mapper
、または同様のものを作成して、次のfilter
ような応答を取得したい:
{
status:"OK",
data:[
{"idLine":"a61dcedb-4a6b-4f8f-bbdd-32cc51e861b2",
"name":"line1",
"code":"pru1"
}]
}
私は何かを試しましObjectMapper
たが、結果はありませんでした。ありがとう。
UPDATE この行は、不正な例外を解析して呼び出す行です (外部ライブラリに属しています)。
result = (JSONObject) new JSONTokener(str).nextValue();
そして、私が解析しようとしている JSON は次のとおりです。
[{"idLine":"a61dcedb-4a6b-4f8f-bbdd-32cc51e861b2","name":"linea1","code":"pru1","colour":"#ff3200","means":"Bus","type":"urban","notes":"","state":true,"timetableInterurbans":[]}]
明確にするために、@ResponseBody を使用して Spring で Pojo をシリアル化し、Android によって応答が取得され、例外をスローする JSONObject を使用して解析されます。
サーバー側の方法:
@RequestMapping(value="/{country}/{cityName}/{type}", method=RequestMethod.GET)
public @ResponseBody List<Line> getUrbanLinesFromCity(@PathVariable String country, @PathVariable String cityName, @PathVariable String type){
//Get the city pojo by country and city name
City city = cityManager.searchCityByCountryAndName(country, cityName);
//Get the lines from the city
List<Line> lines = null;
if (city != null){
lines = lineManager.getLinesByCityAndType(city.getIdCity(), type);
}
return lines;
}