[{"id":1475280000,"high":0.01384629,"low":0.01155011,"area":13251.43990321,"quoteVolume":1073925.2309893,"averagevolume":0.01233925},{"id":1475366400,"high":0.0139987,"low":0.0119,"area":7535.00823446,"quoteVolume":573093.11152305,"averagevolume":0.01314796}]
以上是我想要提取数字的数据。我想从上面的数据中提取id,面积和平均音量,并以以下形式打印结果:
id1:1475280000
area1:13251.43990321
averagevolume1:0.01233925
id2:1475366400
area2:7535.00823446
averagevolume3:0.01314796
答案 0 :(得分:0)
您可以使用jackson fasterxml和ObjectMapper反序列化包装Java对象中值的json对象:
class Values{
//With getters and setters
int id;
double area;
double averageVolume;
//Rest of the values in the json string
}
然后你的反序列化器看起来像:
public class Deserialize {
private final ObjectMapper mapper;
public DeserializeCollectionMessage() {
mapper = new ObjectMapper();
}
public Values deSerializeCollectionMessage(String jsonString) {
Values val = new Values();
return mapper.readValue(jsonString, Values.class);
}
然后,您可以从Values对象
中提取值