私は、暗号化交換から市場データを取得し、ユーザーに情報を表示するかなり簡単なJavaプログラムに取り組んでいます。私はminimal-jsonライブラリを使用しています。ここで名前のないネストされた配列をminimal-jsonで解析する?
は私の現在のコードです:
public class Market {
static JsonArray arrayBittrex;
public static void startTimer(){
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
String url = "https://bittrex.com/api/v1.1/public/getmarketsummaries";
try {
URL url2 = new URL(url);
URLConnection con = url2.openConnection();
InputStream in = con.getInputStream();
String encoding = "UTF-8";
String body = IOUtils.toString(in, encoding);
arrayBittrex = Json.parse(body).asObject().get("result").asArray();
}
catch(MalformedURLException e) {}
catch(IOException e) {}
}
}, 0,5000);
}
public static float getPrice(String exchange, String market) {
for (JsonValue item : arrayBittrex) {
float last = item.asObject().getFloat("Last", 0);
System.out.println(last);
return last;
}
return 0;
}
}
このコードは(https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltcから)例えば、単純なJSON、で動作します:
{
"success" : true,
"message" : "",
"result" : [{
"MarketName" : "BTC-LTC",
"High" : 0.01350000,
"Low" : 0.01200000,
"Volume" : 3833.97619253,
"Last" : 0.01349998
}
]
}
それが適切に配列に "最後の" 値を返します。 。 JSONは(https://bittrex.com/api/v1.1/public/getmarketsummariesのように)複数の配列を持っているとき しかし、このカント作品は:
{
"success" : true,
"message" : "",
"result" : [{
"MarketName" : "BTC-888",
"High" : 0.00000919,
"Low" : 0.00000820,
"Volume" : 74339.61396015,
"Last" : 0.00000820
}, {
"MarketName" : "BTC-A3C",
"High" : 0.00000072,
"Low" : 0.00000001,
"Volume" : 166340678.42280999,
"Last" : 0.00000005
}
]
}
だから私の質問は:どのように私は「MarketName」の値で配列を検索することによって、「最後の」値を得ることができます?
を参照してください>最終値を追加します市場の価値を比較する –