我有一個字符串符號一堆JSON對象:過濾JSON對象
"{\"address\":{\"street\":\"Steenstraat\",\"housenumber\":\"17A\",\"postalcode\":\"6828 CA\",\"city\":\"ARNHEM\",\"geoLocation\":{\"lat\":\"51.983718\",\"lng\":\"5.915553\"}},\"distance\":0,\"type\":\"ING\"}
所以每個JSON對象看起來是這樣的:
{
"address" : {
"street" : "Steenstraat",
"housnumber" : "17A",
"postalcode" : "6828 CA",
"city" : "ARNHEM",
"geolocation" : {
"latitude" : "51.983718",
"longitude" : "54.983718"
}
},
"type" : "citi",
"distance" : 0
}
現在,我使用谷歌的gson庫從其他API中獲取,並給了我一個上面的JSON對象的字符串。我怎樣才能嘗試過濾掉(或者重新定義JSON的結構)來按特定參數對JSON對象進行排序(比如按城市名排序)?
這是我的Atm類。我試圖將JSON字符串轉換爲Atm對象列表。
public class Atm {
private String type;
private Long distance;
private Map<String, String> address = new HashMap<String, String>();
public Atm() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getDistance() {
return distance;
}
public void setDistance(Long distance) {
this.distance = distance;
}
public Map<String, String> getAddress() {
return address;
}
public void setAddress(Map<String, String> address) {
this.address = address;
}
@Override
public String toString() {
return "Atm{" +
"type='" + type +
", distance=" + distance +
", address=" + address.toString() +
'}';
}
}
還是有沒有辦法做到這一點,而無需將其轉換爲Java數據結構?
您需要使用哪種語言? –
Java,最好是 –
這是一個類似的[post](http://stackoverflow.com/questions/19543862/how-can-i-sort-a-jsonarray-in-java) –