亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嵌套 Json 對象數組的 Java 模型

嵌套 Json 對象數組的 Java 模型

米脂 2022-07-20 09:55:48
我正在嘗試研究如何創建模型類以解析來自 Alpha Vantage api 的 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"    }  }}或以圖形形式:元數據顯然是一個由字符串組成的對象:String Information;String Symbol;String LastRefreshed;String OutputSize;String Time Zone;但是當我得到時間序列(每天)時,我被卡住了。這些是我無法解決的問題:對象“時間序列(每日)”,根據功能,標題將更改為時間序列(每月)或時間序列(日內)等。我需要為每個模型創建一個新模型嗎?進一步深入研究“時間序列(每日)”,您實際上擁有時間戳對象的數組列表,但是當我查看文檔時,括號表示一個對象。你會如何引用這個?我在想引用時間對象的方法是獲取時間序列(每日)對象并遍歷它以獲取各個時間時間戳對象,但我不知道您將如何為此創建模型,因為不同每個的時間戳。例如,模型將具有開盤價、最高價、最低價、收盤價、調整后的收盤價、交易量、股息金額、拆分系數,但時間戳在哪里適合呢?我希望這是有道理的,我試圖讓它盡可能清楚,但我理解如果我沒有很好地解釋它。謝謝你的幫助
查看完整描述

1 回答

?
慕少森

TA貢獻2019條經驗 獲得超9個贊

如果您可以調整您的 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"

    }

  ]

}


主要 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);

}


}

類元數據



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);

}


}


課堂時間_系列_每日



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);

}


}


我使用這個網站在線將 JSON 轉換為 POJO。很棒的工具。實時節省。我多希望我能幫忙。


查看完整回答
反對 回復 2022-07-20
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號