Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法分析Groovy中包含大写键的JSON_Json_Rest_Groovy_Escaping - Fatal编程技术网

无法分析Groovy中包含大写键的JSON

无法分析Groovy中包含大写键的JSON,json,rest,groovy,escaping,Json,Rest,Groovy,Escaping,我试图从RESTAPI解析JSON,但当数据的键为大写格式时,无法访问该数据 { "body": { "devices": [{ "_id": "xxxxxxxxxx", "cipher_id": "xxxxxxxx", "last_status_store": 1502808369, "modules": [{ "_id": "xxxxxxx"

我试图从RESTAPI解析JSON,但当数据的键为大写格式时,无法访问该数据

{
    "body": {
        "devices": [{
            "_id": "xxxxxxxxxx",
            "cipher_id": "xxxxxxxx",
            "last_status_store": 1502808369,
            "modules": [{
                "_id": "xxxxxxx",
                "type": "xxxxxxx",
                "last_message": 1502808365,
                "last_seen": 1502808359,
                "dashboard_data": {
                    "time_utc": 1502808359,
                    "Temperature": 18.9,
                    "temp_trend": "down",
                    "Humidity": 27,
                    "date_max_temp": 1502804720,
                    "date_min_temp": 1502808359,
                    "min_temp": 18.9,
                    "max_temp": 22.2
                },
                "data_type": [
                    "Temperature",
                    "Humidity"
                ],
                "last_setup": 1502731328,
                "battery_vp": 6354,
                "battery_percent": 100,
                "rf_status": 67,
                "firmware": 44
            }],
            "place": {
                "altitude": 63.395306309052,
                "city": "xxxxxx",
                "country": "US",
                "timezone": "America/New_York",
                "location": [-72.532673,
                    42.0425917
                ]
            },
            "station_name": "xxxxxxxxxxx",
            "type": "NAMain",
            "dashboard_data": {
                "AbsolutePressure": 1004.6,
                "time_utc": 1502808354,
                "Noise": 50,
                "Temperature": 22.7,
                "temp_trend": "up",
                "Humidity": 69,
                "Pressure": 1012.1,
                "pressure_trend": "stable",
                "CO2": 0,
                "date_max_temp": 1502808290,
                "date_min_temp": 1502801263,
                "min_temp": 21.3,
                "max_temp": 22.7
            },
            "data_type": [
                "Temperature",
                "CO2",
                "Humidity",
                "Noise",
                "Pressure"
            ],
            "co2_calibrating": false,
            "date_setup": 1502731277,
            "last_setup": 1502731277,
            "module_name": "Indoor",
            "firmware": 132,
            "last_upgrade": 1502731279,
            "wifi_status": 51
        }]
    },
    "status": "ok",
    "time_exec": 0.019752025604248,
    "time_server": 1502808443
}
我试图使用Groovy JSON slurper访问JSON,并执行以下命令。在我的debugger.Reponse.content中,响应返回得很好,它是我发送到服务器的HTTPrequest的值

def stationInfo = jsonSlurper.parseText(response.content as String)
def outsideTemp = stationInfo.body.devices.modules.dashboard_data.Temperture    
def outsideHumidty = stationInfo.body.devices.modules.dashboard_data.Humidty    
def insideTemp = stationInfo.body.devices.dashboard_data.Temperture

当我在调试器中查看outsideTemp、outsideHumidty和InsidetTemp时,它们都等于“[null]”。关于为什么会发生这种情况,以及如何解决它,有什么想法吗?编译器是否因为这些是大写字母而假设了什么?

看起来您就快到了

请注意,您附加的json似乎无效,已修复,无法正常工作

def pJson = new groovy.json.JsonSlurper().parseText(response.content as String)
println pJson.body.devices.modules.dashboard_data.Temperature.flatten()
println pJson.body.devices.dashboard_data.Temperature.flatten()
类似于
温度
,您也可以让它在
湿度
下工作


您可以在

中看到同样的情况,我们是否假设仪表板数据中的其他元素返回正确?(如果可以,请在问题中明确说明。)问题可能在于
设备
是一个数组,应该由
[index]
访问,而您将其视为普通对象,与
“模块”
相同,json中的所有内容都正确返回,通过这种方式引用其他字段(普通对象)我没有问题。另外需要注意的是,当我引用它们时,这些大写值会在语法上突出显示,但如果保留小写,它们就不会了。非常感谢。我还错报了温度和湿度,这对我没有帮助。