JSON對象檢索數據我有一個對象:從紅寶石
EURO_COUNTRIES = ['France', 'Germany', 'Spain']
fruit_production = {
cuba: {
#meaning: country c produces k kilograms of fruit in region r for season s
winter: [{north: 1}, {south: nil}, {east: 4}, {west: 4}],
summer: [{north: nil}, {south: 5}, {east: ""}, {west: 5}],
},
spain: {
fall: [{north: 7}, {}],
summer: [{north: nil}, {south: "5"}, {east: 2}, {west: '5'}],
spring: []
}
#and the list goes on for hundreds of countries
}fruit_production = {
cuba: {
#meaning: country c produces k kilograms of fruit in region r for season s
winter: [{north: 1}, {south: nil}, {east: 4}, {west: 4}],
summer: [{north: nil}, {south: 5}, {east: ""}, {west: 5}],
},
spain: {
fall: [{north: 7}, {}],
summer: [{north: nil}, {south: "5"}, {east: 2}, {west: '5'}],
spring: []
}
#and the list goes on for hundreds of countries
}
我試圖把它與json.parse(fruit_production)轉換成JSON對象,但我怎麼能真正從中得到的數據並在此之後循環?例如:
- 返回該國最高的全年水果產量
- 返回歐洲國家最高溫暖的季節(春,夏)果實產量
- 返回來自全國映射佔全年總產量,即{荷蘭:1818,泰國:8200等}
- 返回每個區域的全球總產量的映射,例如{north:28333,south:91339,east:14343,west:50290}