简体   繁体   English

从Java中的JSON数组获取价值

[英]Getting value from json array in java

How can i get value from json array in java Output 我如何从java输出中的json数组获取值

{
    "result": "success",
    "from": "USD",
    "rates": {
        "AUD": ((AUD in terms of USD)),
        "BGN": 1.8096,
        "BRL": 3.1143,
        "...": 1.3113,
        "...": 7.473, etc. etc.
    }
}

How do i get the value of "BGN" 我如何获得“ BGN”的价值

What you have above is not a JSON array. 您上面没有的不是JSON数组。

JSON arrays looks like this: JSON数组如下所示:

{
 "this-is-an-array": [1, 2, 3, 4, 5]
}

What you have above are properties of an object designated to the property rates. 上面的内容是指定给属性费率的对象的属性。 Think of JSON as a Map of Maps and Arrays. 可以将JSON视为地图和数组的地图。

Below, I show you how you can iterate the properties in JavaScript. 下面,我向您展示如何在JavaScript中迭代属性。 It may look like its an array but its actually a map that you access providing the key: 它可能看起来像是一个数组,但实际上是您提供键即可访问的映射:

 var json = { "result": "success", "from": "USD", "rates": { /* "AUD": ((AUD in terms of USD)), This is not JSON. It is something else */ "BGN": 1.8096, "BRL": 3.1143, "...": 1.3113 } }; for(var prop in json.rates){ console.log("Key: " + prop + ", Value: " + json.rates[prop]); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM