[英]Java model for arrays of nested Json objects
I am trying to work out how to create the model class/s for parsing Json data from Alpha Vantage api but have not been able to workout the format for the model class. 我正在尝试找出如何创建模型类来解析来自Alpha Vantage api的Json数据的方法,但还无法对模型类的格式进行锻炼。
This is the format of the Json: 这是Json的格式:
{
"Meta Data": {
"1. Information": "Daily Time Series with Splits and Dividend Events",
"2. Symbol": "FCHI",
"3. Last Refreshed": "2015-08-21",
"4. Output Size": "Full size",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2015-08-21": {
"1. open": "47.4100",
"2. high": "47.9100",
"3. low": "47.4100",
"4. close": "47.9100",
"5. adjusted close": "47.9100",
"6. volume": "5148",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
},
"2015-08-20": {
"1. open": "47.9000",
"2. high": "47.9000",
"3. low": "47.0600",
"4. close": "47.2900",
"5. adjusted close": "47.2900",
"6. volume": "661",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000"
}
}
}
or in graphical form: 或以图形形式:
Meta data is obviously an object made up of the strings: 元数据显然是由字符串组成的对象:
String Information;
String Symbol;
String LastRefreshed;
String OutputSize;
String Time Zone;
But when I get Time Series (daily) I am stuck. 但是,当我获得“时间序列”(每天)时,我会陷入困境。 These are the questions I haven't been able to work out: 这些是我无法解决的问题:
I hope that makes sense, I tried to make it as clear as possible but I understand if I didn't explain it very well. 我希望这是有道理的,我试图使其尽可能清晰,但我理解如果我没有很好地解释它。
Thanks for your help 谢谢你的帮助
If you could tweak your JSON response to match it to this below , you could achieve the feature you're trying with ease 如果您可以调整JSON响应以使其与以下内容匹配,则可以轻松实现您正在尝试的功能
{
"Meta Data": {
"1. Information": "Daily Time Series with Splits and Dividend Events",
"2. Symbol": "FCHI",
"3. Last Refreshed": "2015-08-21",
"4. Output Size": "Full size",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": [
{
"1. open": "47.4100",
"2. high": "47.9100",
"3. low": "47.4100",
"4. close": "47.9100",
"5. adjusted close": "47.9100",
"6. volume": "5148",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000",
"time_stamp": "2015-08-21"
},
{
"1. open": "47.9000",
"2. high": "47.9000",
"3. low": "47.0600",
"4. close": "47.2900",
"5. adjusted close": "47.2900",
"6. volume": "661",
"7. dividend amount": "0.0000",
"8. split coefficient": "1.0000",
"time_stamp": "2015-08-20"
}
]
}
The Main POJO 主要POJO
package com.example;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Example {
private Meta_Data meta_Data;
private List<Time_Series__Daily_> time_Series__Daily_ = null;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public Meta_Data getMeta_Data() {
return meta_Data;
}
public void setMeta_Data(Meta_Data meta_Data) {
this.meta_Data = meta_Data;
}
public List<Time_Series__Daily_> getTime_Series__Daily_() {
return time_Series__Daily_;
}
public void setTime_Series__Daily_(List<Time_Series__Daily_> time_Series__Daily_) {
this.time_Series__Daily_ = time_Series__Daily_;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
The Class MetaData 类元数据
package com.example;
import java.util.HashMap;
import java.util.Map;
public class Meta_Data {
private String _1__Information;
private String _2__Symbol;
private String _3__Last_Refreshed;
private String _4__Output_Size;
private String _5__Time_Zone;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public String get1__Information() {
return _1__Information;
}
public void set1__Information(String _1__Information) {
this._1__Information = _1__Information;
}
public String get2__Symbol() {
return _2__Symbol;
}
public void set2__Symbol(String _2__Symbol) {
this._2__Symbol = _2__Symbol;
}
public String get3__Last_Refreshed() {
return _3__Last_Refreshed;
}
public void set3__Last_Refreshed(String _3__Last_Refreshed) {
this._3__Last_Refreshed = _3__Last_Refreshed;
}
public String get4__Output_Size() {
return _4__Output_Size;
}
public void set4__Output_Size(String _4__Output_Size) {
this._4__Output_Size = _4__Output_Size;
}
public String get5__Time_Zone() {
return _5__Time_Zone;
}
public void set5__Time_Zone(String _5__Time_Zone) {
this._5__Time_Zone = _5__Time_Zone;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
The Class Time_Series_Daily 班级Time_Series_Daily
package com.example;
import java.util.HashMap;
import java.util.Map;
public class Time_Series__Daily_ {
private String _1__open;
private String _2__high;
private String _3__low;
private String _4__close;
private String _5__adjusted_close;
private String _6__volume;
private String _7__dividend_amount;
private String _8__split_coefficient;
private String time_stamp;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public String get1__open() {
return _1__open;
}
public void set1__open(String _1__open) {
this._1__open = _1__open;
}
public String get2__high() {
return _2__high;
}
public void set2__high(String _2__high) {
this._2__high = _2__high;
}
public String get3__low() {
return _3__low;
}
public void set3__low(String _3__low) {
this._3__low = _3__low;
}
public String get4__close() {
return _4__close;
}
public void set4__close(String _4__close) {
this._4__close = _4__close;
}
public String get5__adjusted_close() {
return _5__adjusted_close;
}
public void set5__adjusted_close(String _5__adjusted_close) {
this._5__adjusted_close = _5__adjusted_close;
}
public String get6__volume() {
return _6__volume;
}
public void set6__volume(String _6__volume) {
this._6__volume = _6__volume;
}
public String get7__dividend_amount() {
return _7__dividend_amount;
}
public void set7__dividend_amount(String _7__dividend_amount) {
this._7__dividend_amount = _7__dividend_amount;
}
public String get8__split_coefficient() {
return _8__split_coefficient;
}
public void set8__split_coefficient(String _8__split_coefficient) {
this._8__split_coefficient = _8__split_coefficient;
}
public String getTime_stamp() {
return time_stamp;
}
public void setTime_stamp(String time_stamp) {
this.time_stamp = time_stamp;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
I used this website to convert JSON to POJO online. 我使用此网站在线将JSON转换为POJO。 Great tool. 很棒的工具。 Real time saver. 实时保护程序。 I wish i could help. 我多希望我能帮忙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.