Ccmmutty logo
Commutty IT
0 pv31 min read

GO JSONのパース方法についての備忘録

https://cdn.magicode.io/media/notebox/f0a4f7d7-c26f-4530-854c-5abb00c6e6bf.jpeg

はじめに

ネストが深くて配列もあるJSONのパース方法に悩んだので備忘録として残します。

環境

  • macOS Monterey 12.3.1
  • Go 1.18.1

パースしようとしたJSON

YahooFinanceAPIのレスポンスを例に説明していきます。 構造としては"quoteResponse"の中に"error","result"があり、 "result"は配列でその中には"ask"〜"twoHundredDayAverageChangePercent"があります。

JSONのレスポンス例

{
  "quoteResponse": {
    "error": null,
    "result": [
      {
        "ask": 117.27,
        "askSize": 8,
        "averageDailyVolume10Day": 233119800,
        "averageDailyVolume3Month": 170533131,
        "bid": 117.25,
        "bidSize": 22,
        "bookValue": 4.218,
        "currency": "USD",
        "displayName": "Apple",
        "dividendDate": 1597276800,
        "earningsTimestamp": 1596126600,
        "earningsTimestampEnd": 1604318400,
        "earningsTimestampStart": 1603882740,
        "epsCurrentYear": 3.23,
        "epsForward": 3.86,
        "epsTrailingTwelveMonths": 3.296,
        "esgPopulated": false,
        "exchange": "NMS",
        "exchangeDataDelayedBy": 0,
        "exchangeTimezoneName": "America/New_York",
        "exchangeTimezoneShortName": "EDT",
        "fiftyDayAverage": 112.823425,
        "fiftyDayAverageChange": 4.4965744,
        "fiftyDayAverageChangePercent": 0.03985497,
        "fiftyTwoWeekHigh": 137.98,
        "fiftyTwoWeekHighChange": -20.659996,
        "fiftyTwoWeekHighChangePercent": -0.14973181,
        "fiftyTwoWeekLow": 53.1525,
        "fiftyTwoWeekLowChange": 64.167496,
        "fiftyTwoWeekLowChangePercent": 1.2072338,
        "fiftyTwoWeekRange": "53.1525 - 137.98",
        "financialCurrency": "USD",
        "firstTradeDateMilliseconds": 345479400000,
        "forwardPE": 30.393784,
        "fullExchangeName": "NasdaqGS",
        "gmtOffSetMilliseconds": -14400000,
        "language": "en-US",
        "longName": "Apple Inc.",
        "market": "us_market",
        "marketCap": 2006465249280,
        "marketState": "POST",
        "messageBoardId": "finmb_24937",
        "postMarketChange": -0.25,
        "postMarketChangePercent": -0.2130924,
        "postMarketPrice": 117.07,
        "postMarketTime": 1599686591,
        "priceEpsCurrentYear": 36.32198,
        "priceHint": 2,
        "priceToBook": 27.81413,
        "quoteSourceName": "Nasdaq Real Time Price",
        "quoteType": "EQUITY",
        "region": "US",
        "regularMarketChange": 4.5,
        "regularMarketChangePercent": 3.9886546,
        "regularMarketDayHigh": 119.14,
        "regularMarketDayLow": 115.26,
        "regularMarketDayRange": "115.26 - 119.14",
        "regularMarketOpen": 117.26,
        "regularMarketPreviousClose": 112.82,
        "regularMarketPrice": 117.32,
        "regularMarketTime": 1599681602,
        "regularMarketVolume": 168404235,
        "sharesOutstanding": 17102499840,
        "shortName": "Apple Inc.",
        "sourceInterval": 15,
        "symbol": "AAPL",
        "tradeable": false,
        "trailingAnnualDividendRate": 0.782,
        "trailingAnnualDividendYield": 0.0069313953,
        "trailingPE": 35.59466,
        "triggerable": true,
        "twoHundredDayAverage": 85.99835,
        "twoHundredDayAverageChange": 31.321648,
        "twoHundredDayAverageChangePercent": 0.3642122
      },
      {
        "ask": 211.63,
        "askSize": 9,
        "averageDailyVolume10Day": 43250000,
        "averageDailyVolume3Month": 35562815,
        "bid": 211.25,
        "bidSize": 9,
        "bookValue": 15.626,
        "currency": "USD",
        "displayName": "Microsoft",
        "dividendDate": 1599696000,
        "earningsTimestamp": 1595434164,
        "earningsTimestampEnd": 1603742400,
        "earningsTimestampStart": 1603310400,
        "epsCurrentYear": 6.46,
        "epsForward": 7.34,
        "epsTrailingTwelveMonths": 5.76,
        "esgPopulated": false,
        "exchange": "NMS",
        "exchangeDataDelayedBy": 0,
        "exchangeTimezoneName": "America/New_York",
        "exchangeTimezoneShortName": "EDT",
        "fiftyDayAverage": 212.50658,
        "fiftyDayAverageChange": -1.2165833,
        "fiftyDayAverageChangePercent": -0.0057249204,
        "fiftyTwoWeekHigh": 232.86,
        "fiftyTwoWeekHighChange": -21.570007,
        "fiftyTwoWeekHighChangePercent": -0.092630796,
        "fiftyTwoWeekLow": 132.52,
        "fiftyTwoWeekLowChange": 78.76999,
        "fiftyTwoWeekLowChangePercent": 0.59440076,
        "fiftyTwoWeekRange": "132.52 - 232.86",
        "financialCurrency": "USD",
        "firstTradeDateMilliseconds": 511108200000,
        "forwardPE": 28.786102,
        "fullExchangeName": "NasdaqGS",
        "gmtOffSetMilliseconds": -14400000,
        "language": "en-US",
        "longName": "Microsoft Corporation",
        "market": "us_market",
        "marketCap": 1598968692736,
        "marketState": "POST",
        "messageBoardId": "finmb_21835",
        "postMarketChange": -61.5672,
        "postMarketChangePercent": -29.13872,
        "postMarketPrice": 149.7228,
        "postMarketTime": 1599686588,
        "priceEpsCurrentYear": 32.707428,
        "priceHint": 2,
        "priceToBook": 13.521694,
        "quoteSourceName": "Nasdaq Real Time Price",
        "quoteType": "EQUITY",
        "region": "US",
        "regularMarketChange": 8.62999,
        "regularMarketChangePercent": 4.2583585,
        "regularMarketDayHigh": 214.8399,
        "regularMarketDayLow": 206.7,
        "regularMarketDayRange": "206.7 - 214.8399",
        "regularMarketOpen": 207.6,
        "regularMarketPreviousClose": 202.66,
        "regularMarketPrice": 211.29,
        "regularMarketTime": 1599681601,
        "regularMarketVolume": 43764495,
        "sharesOutstanding": 7567649792,
        "shortName": "Microsoft Corporation",
        "sourceInterval": 15,
        "symbol": "MSFT",
        "tradeable": false,
        "trailingAnnualDividendRate": 2.04,
        "trailingAnnualDividendYield": 0.01006612,
        "trailingPE": 36.68229,
        "triggerable": true,
        "twoHundredDayAverage": 186.7529,
        "twoHundredDayAverageChange": 24.537094,
        "twoHundredDayAverageChangePercent": 0.13138802
      }
    ]
  }
}

どのように構造体を定義すればよいか

方法1

シンプルにJSON-TO-GOで生成された定義のまま
type Quote struct {
	QuoteResponse struct {
		Error  interface{} `json:"error"`
		Result []struct {
			Ask                               float64 `json:"ask"`
			AskSize                           int     `json:"askSize"`
			AverageDailyVolume10Day           int     `json:"averageDailyVolume10Day"`
			AverageDailyVolume3Month          int     `json:"averageDailyVolume3Month"`
			Bid                               float64 `json:"bid"`
			BidSize                           int     `json:"bidSize"`
			BookValue                         float64 `json:"bookValue"`
			Currency                          string  `json:"currency"`
			DisplayName                       string  `json:"displayName"`
			DividendDate                      int     `json:"dividendDate"`
			EarningsTimestamp                 int     `json:"earningsTimestamp"`
			EarningsTimestampEnd              int     `json:"earningsTimestampEnd"`
			EarningsTimestampStart            int     `json:"earningsTimestampStart"`
			EpsCurrentYear                    float64 `json:"epsCurrentYear"`
			EpsForward                        float64 `json:"epsForward"`
			EpsTrailingTwelveMonths           float64 `json:"epsTrailingTwelveMonths"`
			EsgPopulated                      bool    `json:"esgPopulated"`
			Exchange                          string  `json:"exchange"`
			ExchangeDataDelayedBy             int     `json:"exchangeDataDelayedBy"`
			ExchangeTimezoneName              string  `json:"exchangeTimezoneName"`
			ExchangeTimezoneShortName         string  `json:"exchangeTimezoneShortName"`
			FiftyDayAverage                   float64 `json:"fiftyDayAverage"`
			FiftyDayAverageChange             float64 `json:"fiftyDayAverageChange"`
			FiftyDayAverageChangePercent      float64 `json:"fiftyDayAverageChangePercent"`
			FiftyTwoWeekHigh                  float64 `json:"fiftyTwoWeekHigh"`
			FiftyTwoWeekHighChange            float64 `json:"fiftyTwoWeekHighChange"`
			FiftyTwoWeekHighChangePercent     float64 `json:"fiftyTwoWeekHighChangePercent"`
			FiftyTwoWeekLow                   float64 `json:"fiftyTwoWeekLow"`
			FiftyTwoWeekLowChange             float64 `json:"fiftyTwoWeekLowChange"`
			FiftyTwoWeekLowChangePercent      float64 `json:"fiftyTwoWeekLowChangePercent"`
			FiftyTwoWeekRange                 string  `json:"fiftyTwoWeekRange"`
			FinancialCurrency                 string  `json:"financialCurrency"`
			FirstTradeDateMilliseconds        int64   `json:"firstTradeDateMilliseconds"`
			ForwardPE                         float64 `json:"forwardPE"`
			FullExchangeName                  string  `json:"fullExchangeName"`
			GmtOffSetMilliseconds             int     `json:"gmtOffSetMilliseconds"`
			Language                          string  `json:"language"`
			LongName                          string  `json:"longName"`
			Market                            string  `json:"market"`
			MarketCap                         int64   `json:"marketCap"`
			MarketState                       string  `json:"marketState"`
			MessageBoardID                    string  `json:"messageBoardId"`
			PostMarketChange                  float64 `json:"postMarketChange"`
			PostMarketChangePercent           float64 `json:"postMarketChangePercent"`
			PostMarketPrice                   float64 `json:"postMarketPrice"`
			PostMarketTime                    int     `json:"postMarketTime"`
			PriceEpsCurrentYear               float64 `json:"priceEpsCurrentYear"`
			PriceHint                         int     `json:"priceHint"`
			PriceToBook                       float64 `json:"priceToBook"`
			QuoteSourceName                   string  `json:"quoteSourceName"`
			QuoteType                         string  `json:"quoteType"`
			Region                            string  `json:"region"`
			RegularMarketChange               float64 `json:"regularMarketChange"`
			RegularMarketChangePercent        float64 `json:"regularMarketChangePercent"`
			RegularMarketDayHigh              float64 `json:"regularMarketDayHigh"`
			RegularMarketDayLow               float64 `json:"regularMarketDayLow"`
			RegularMarketDayRange             string  `json:"regularMarketDayRange"`
			RegularMarketOpen                 float64 `json:"regularMarketOpen"`
			RegularMarketPreviousClose        float64 `json:"regularMarketPreviousClose"`
			RegularMarketPrice                float64 `json:"regularMarketPrice"`
			RegularMarketTime                 int     `json:"regularMarketTime"`
			RegularMarketVolume               int     `json:"regularMarketVolume"`
			SharesOutstanding                 int64   `json:"sharesOutstanding"`
			ShortName                         string  `json:"shortName"`
			SourceInterval                    int     `json:"sourceInterval"`
			Symbol                            string  `json:"symbol"`
			Tradeable                         bool    `json:"tradeable"`
			TrailingAnnualDividendRate        float64 `json:"trailingAnnualDividendRate"`
			TrailingAnnualDividendYield       float64 `json:"trailingAnnualDividendYield"`
			TrailingPE                        float64 `json:"trailingPE"`
			Triggerable                       bool    `json:"triggerable"`
			TwoHundredDayAverage              float64 `json:"twoHundredDayAverage"`
			TwoHundredDayAverageChange        float64 `json:"twoHundredDayAverageChange"`
			TwoHundredDayAverageChangePercent float64 `json:"twoHundredDayAverageChangePercent"`
		} `json:"result"`
	} `json:"quoteResponse"`
}

方法2

階層ごとに構造体を定義する。
type Quote struct {
	QuoteResponse QuoteResponse `json:"quoteResponse"`
}

type QuoteResponse struct {
	Error  interface{} `json:"error"`
	Result []Result    `json:"result"`
}

type Result struct {
	Ask                               float64 `json:"ask"`
	AskSize                           int     `json:"askSize"`
	AverageDailyVolume10Day           int     `json:"averageDailyVolume10Day"`
	AverageDailyVolume3Month          int     `json:"averageDailyVolume3Month"`
	Bid                               float64 `json:"bid"`
	BidSize                           int     `json:"bidSize"`
	BookValue                         float64 `json:"bookValue"`
	Currency                          string  `json:"currency"`
	DisplayName                       string  `json:"displayName"`
	DividendDate                      int     `json:"dividendDate"`
	EarningsTimestamp                 int     `json:"earningsTimestamp"`
	EarningsTimestampEnd              int     `json:"earningsTimestampEnd"`
	EarningsTimestampStart            int     `json:"earningsTimestampStart"`
	EpsCurrentYear                    float64 `json:"epsCurrentYear"`
	EpsForward                        float64 `json:"epsForward"`
	EpsTrailingTwelveMonths           float64 `json:"epsTrailingTwelveMonths"`
	EsgPopulated                      bool    `json:"esgPopulated"`
	Exchange                          string  `json:"exchange"`
	ExchangeDataDelayedBy             int     `json:"exchangeDataDelayedBy"`
	ExchangeTimezoneName              string  `json:"exchangeTimezoneName"`
	ExchangeTimezoneShortName         string  `json:"exchangeTimezoneShortName"`
	FiftyDayAverage                   float64 `json:"fiftyDayAverage"`
	FiftyDayAverageChange             float64 `json:"fiftyDayAverageChange"`
	FiftyDayAverageChangePercent      float64 `json:"fiftyDayAverageChangePercent"`
	FiftyTwoWeekHigh                  float64 `json:"fiftyTwoWeekHigh"`
	FiftyTwoWeekHighChange            float64 `json:"fiftyTwoWeekHighChange"`
	FiftyTwoWeekHighChangePercent     float64 `json:"fiftyTwoWeekHighChangePercent"`
	FiftyTwoWeekLow                   float64 `json:"fiftyTwoWeekLow"`
	FiftyTwoWeekLowChange             float64 `json:"fiftyTwoWeekLowChange"`
	FiftyTwoWeekLowChangePercent      float64 `json:"fiftyTwoWeekLowChangePercent"`
	FiftyTwoWeekRange                 string  `json:"fiftyTwoWeekRange"`
	FinancialCurrency                 string  `json:"financialCurrency"`
	FirstTradeDateMilliseconds        int64   `json:"firstTradeDateMilliseconds"`
	ForwardPE                         float64 `json:"forwardPE"`
	FullExchangeName                  string  `json:"fullExchangeName"`
	GmtOffSetMilliseconds             int     `json:"gmtOffSetMilliseconds"`
	Language                          string  `json:"language"`
	LongName                          string  `json:"longName"`
	Market                            string  `json:"market"`
	MarketCap                         int64   `json:"marketCap"`
	MarketState                       string  `json:"marketState"`
	MessageBoardID                    string  `json:"messageBoardId"`
	PostMarketChange                  float64 `json:"postMarketChange"`
	PostMarketChangePercent           float64 `json:"postMarketChangePercent"`
	PostMarketPrice                   float64 `json:"postMarketPrice"`
	PostMarketTime                    int     `json:"postMarketTime"`
	PriceEpsCurrentYear               float64 `json:"priceEpsCurrentYear"`
	PriceHint                         int     `json:"priceHint"`
	PriceToBook                       float64 `json:"priceToBook"`
	QuoteSourceName                   string  `json:"quoteSourceName"`
	QuoteType                         string  `json:"quoteType"`
	Region                            string  `json:"region"`
	RegularMarketChange               float64 `json:"regularMarketChange"`
	RegularMarketChangePercent        float64 `json:"regularMarketChangePercent"`
	RegularMarketDayHigh              float64 `json:"regularMarketDayHigh"`
	RegularMarketDayLow               float64 `json:"regularMarketDayLow"`
	RegularMarketDayRange             string  `json:"regularMarketDayRange"`
	RegularMarketOpen                 float64 `json:"regularMarketOpen"`
	RegularMarketPreviousClose        float64 `json:"regularMarketPreviousClose"`
	RegularMarketPrice                float64 `json:"regularMarketPrice"`
	RegularMarketTime                 int     `json:"regularMarketTime"`
	RegularMarketVolume               int     `json:"regularMarketVolume"`
	SharesOutstanding                 int64   `json:"sharesOutstanding"`
	ShortName                         string  `json:"shortName"`
	SourceInterval                    int     `json:"sourceInterval"`
	Symbol                            string  `json:"symbol"`
	Tradeable                         bool    `json:"tradeable"`
	TrailingAnnualDividendRate        float64 `json:"trailingAnnualDividendRate"`
	TrailingAnnualDividendYield       float64 `json:"trailingAnnualDividendYield"`
	TrailingPE                        float64 `json:"trailingPE"`
	Triggerable                       bool    `json:"triggerable"`
	TwoHundredDayAverage              float64 `json:"twoHundredDayAverage"`
	TwoHundredDayAverageChange        float64 `json:"twoHundredDayAverageChange"`
	TwoHundredDayAverageChangePercent float64 `json:"twoHundredDayAverageChangePercent"`
}

値を出力してみる

実際に値を取り出す際の実行例を示します。 値の取り出し方については方法1、方法2共に同じです。
試してみるときはあらかじめ「JSONのレスポンス例」で示したデータをmain.goと同じ階層に「test.json」として保存しておいてください。
package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

type Quote struct {
	QuoteResponse struct {
		Error  interface{} `json:"error"`
		Result []struct {
			Ask                               float64 `json:"ask"`
			AskSize                           int     `json:"askSize"`
			AverageDailyVolume10Day           int     `json:"averageDailyVolume10Day"`
			AverageDailyVolume3Month          int     `json:"averageDailyVolume3Month"`
			Bid                               float64 `json:"bid"`
			BidSize                           int     `json:"bidSize"`
			BookValue                         float64 `json:"bookValue"`
			Currency                          string  `json:"currency"`
			DisplayName                       string  `json:"displayName"`
			DividendDate                      int     `json:"dividendDate"`
			EarningsTimestamp                 int     `json:"earningsTimestamp"`
			EarningsTimestampEnd              int     `json:"earningsTimestampEnd"`
			EarningsTimestampStart            int     `json:"earningsTimestampStart"`
			EpsCurrentYear                    float64 `json:"epsCurrentYear"`
			EpsForward                        float64 `json:"epsForward"`
			EpsTrailingTwelveMonths           float64 `json:"epsTrailingTwelveMonths"`
			EsgPopulated                      bool    `json:"esgPopulated"`
			Exchange                          string  `json:"exchange"`
			ExchangeDataDelayedBy             int     `json:"exchangeDataDelayedBy"`
			ExchangeTimezoneName              string  `json:"exchangeTimezoneName"`
			ExchangeTimezoneShortName         string  `json:"exchangeTimezoneShortName"`
			FiftyDayAverage                   float64 `json:"fiftyDayAverage"`
			FiftyDayAverageChange             float64 `json:"fiftyDayAverageChange"`
			FiftyDayAverageChangePercent      float64 `json:"fiftyDayAverageChangePercent"`
			FiftyTwoWeekHigh                  float64 `json:"fiftyTwoWeekHigh"`
			FiftyTwoWeekHighChange            float64 `json:"fiftyTwoWeekHighChange"`
			FiftyTwoWeekHighChangePercent     float64 `json:"fiftyTwoWeekHighChangePercent"`
			FiftyTwoWeekLow                   float64 `json:"fiftyTwoWeekLow"`
			FiftyTwoWeekLowChange             float64 `json:"fiftyTwoWeekLowChange"`
			FiftyTwoWeekLowChangePercent      float64 `json:"fiftyTwoWeekLowChangePercent"`
			FiftyTwoWeekRange                 string  `json:"fiftyTwoWeekRange"`
			FinancialCurrency                 string  `json:"financialCurrency"`
			FirstTradeDateMilliseconds        int64   `json:"firstTradeDateMilliseconds"`
			ForwardPE                         float64 `json:"forwardPE"`
			FullExchangeName                  string  `json:"fullExchangeName"`
			GmtOffSetMilliseconds             int     `json:"gmtOffSetMilliseconds"`
			Language                          string  `json:"language"`
			LongName                          string  `json:"longName"`
			Market                            string  `json:"market"`
			MarketCap                         int64   `json:"marketCap"`
			MarketState                       string  `json:"marketState"`
			MessageBoardID                    string  `json:"messageBoardId"`
			PostMarketChange                  float64 `json:"postMarketChange"`
			PostMarketChangePercent           float64 `json:"postMarketChangePercent"`
			PostMarketPrice                   float64 `json:"postMarketPrice"`
			PostMarketTime                    int     `json:"postMarketTime"`
			PriceEpsCurrentYear               float64 `json:"priceEpsCurrentYear"`
			PriceHint                         int     `json:"priceHint"`
			PriceToBook                       float64 `json:"priceToBook"`
			QuoteSourceName                   string  `json:"quoteSourceName"`
			QuoteType                         string  `json:"quoteType"`
			Region                            string  `json:"region"`
			RegularMarketChange               float64 `json:"regularMarketChange"`
			RegularMarketChangePercent        float64 `json:"regularMarketChangePercent"`
			RegularMarketDayHigh              float64 `json:"regularMarketDayHigh"`
			RegularMarketDayLow               float64 `json:"regularMarketDayLow"`
			RegularMarketDayRange             string  `json:"regularMarketDayRange"`
			RegularMarketOpen                 float64 `json:"regularMarketOpen"`
			RegularMarketPreviousClose        float64 `json:"regularMarketPreviousClose"`
			RegularMarketPrice                float64 `json:"regularMarketPrice"`
			RegularMarketTime                 int     `json:"regularMarketTime"`
			RegularMarketVolume               int     `json:"regularMarketVolume"`
			SharesOutstanding                 int64   `json:"sharesOutstanding"`
			ShortName                         string  `json:"shortName"`
			SourceInterval                    int     `json:"sourceInterval"`
			Symbol                            string  `json:"symbol"`
			Tradeable                         bool    `json:"tradeable"`
			TrailingAnnualDividendRate        float64 `json:"trailingAnnualDividendRate"`
			TrailingAnnualDividendYield       float64 `json:"trailingAnnualDividendYield"`
			TrailingPE                        float64 `json:"trailingPE"`
			Triggerable                       bool    `json:"triggerable"`
			TwoHundredDayAverage              float64 `json:"twoHundredDayAverage"`
			TwoHundredDayAverageChange        float64 `json:"twoHundredDayAverageChange"`
			TwoHundredDayAverageChangePercent float64 `json:"twoHundredDayAverageChangePercent"`
		} `json:"result"`
	} `json:"quoteResponse"`
}

func main() {
	file, err := ioutil.ReadFile("./test.json")
	if err != nil {
		log.Println("ReadError: ", err)
		os.Exit(1)
	}

	var quote Quote
	json.Unmarshal(file, &quote)

	fmt.Println("quoteの値すべてを出力")
	fmt.Println(quote)
	fmt.Println("Resultの1番目の配列のAskのみ取り出す")
	fmt.Println(quote.QuoteResponse.Result[0].Ask)

}


実行結果
quoteの値すべてを出力
{{<nil> [{117.27 8 233119800 170533131 117.25 22 4.218 USD Apple 1597276800 1596126600 1604318400 1603882740 3.23 3.86 3.296 false NMS 0 America/New_York EDT 112.823425 4.4965744 0.03985497 137.98 -20.659996 -0.14973181 53.1525 64.167496 1.2072338 53.1525 - 137.98 USD 345479400000 30.393784 NasdaqGS -14400000 en-US Apple Inc. us_market 2006465249280 POST finmb_24937 -0.25 -0.2130924 117.07 1599686591 36.32198 2 27.81413 Nasdaq Real Time Price EQUITY US 4.5 3.9886546 119.14 115.26 115.26 - 119.14 117.26 112.82 117.32 1599681602 168404235 17102499840 Apple Inc. 15 AAPL false 0.782 0.0069313953 35.59466 true 85.99835 31.321648 0.3642122} {211.63 9 43250000 35562815 211.25 9 15.626 USD Microsoft 1599696000 1595434164 1603742400 1603310400 6.46 7.34 5.76 false NMS 0 America/New_York EDT 212.50658 -1.2165833 -0.0057249204 232.86 -21.570007 -0.092630796 132.52 78.76999 0.59440076 132.52 - 232.86 USD 511108200000 28.786102 NasdaqGS -14400000 en-US Microsoft Corporation us_market 1598968692736 POST finmb_21835 -61.5672 -29.13872 149.7228 1599686588 32.707428 2 13.521694 Nasdaq Real Time Price EQUITY US 8.62999 4.2583585 214.8399 206.7 206.7 - 214.8399 207.6 202.66 211.29 1599681601 43764495 7567649792 Microsoft Corporation 15 MSFT false 2.04 0.01006612 36.68229 true 186.7529 24.537094 0.13138802}]}}
Resultの1番目の配列のAskのみ取り出す
117.27

まとめ

JSON -TO-GOのありがたみを感じました。なんて楽なんでしょう。 理解してしまえばなんてことはないので今後はつまずかずにできそうです。

Discussion

コメントにはログインが必要です。