Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Arrays 如何从嵌套/交错Excel对象中获取值-json中的数据_Arrays_Json_Excel_Object_Vba - Fatal编程技术网

Arrays 如何从嵌套/交错Excel对象中获取值-json中的数据

Arrays 如何从嵌套/交错Excel对象中获取值-json中的数据,arrays,json,excel,object,vba,Arrays,Json,Excel,Object,Vba,我已经尝试了许多用于Excel的JSON加载项,但是我没有机会解析下面的JSON数据。最后,我成功地使用了下面的代码 Sub jsonDecode() Dim jsonDecode As Variant jsonText = Worksheets("Sheet3").Range("A1").Value Set sc = CreateObject("ScriptControl"): sc.Language = "JScript" Set jsonDecode = sc.

我已经尝试了许多用于Excel的JSON加载项,但是我没有机会解析下面的JSON数据。最后,我成功地使用了下面的代码

Sub jsonDecode()
   Dim jsonDecode As Variant
   jsonText = Worksheets("Sheet3").Range("A1").Value
    Set sc = CreateObject("ScriptControl"): sc.Language = "JScript"
    Set jsonDecode = sc.Eval("(" + jsonText + ")")
End Sub
创建交错对象,但无法访问下图中的值。 我试过以下方法

msgbox(jsonDecode.location.id)
msgbox(tostring(jsonDecode.location.id))
msgbox(jsonDecode(location(id)))
如果代码能够获得下图中标记为A和B的值,我们将不胜感激:) 如果我的术语有点偏颇,请原谅

干杯

JSON文本是

{“地点”:{“id”:2456,“名称”:“图格拉”,“地区”:“中央海岸”,“州”:“新南威尔士州”,“邮编”:“2259”,“时区”:“澳大利亚/悉尼”,“拉丁美洲”:-33.30701,“液化天然气”:151.4159,“类型id”:1},“天气”:{“天”:[{“日期时间”:“2016-09-13 00:00:00:00”,“条目”:[{“日期时间”:“2016-09-13 00:00:00”,“普雷西斯科德”:“阵雨”,“普雷西斯克斯”:“晚雨”,“precisOverlayCode”:“night”:false,“min”:10,“max”:22}],“units”:{“temperature”:“c”},“IssuedAtime”:“2016-09-13 11:35:20”;“wind”:{“dateTime”:“2016-09-13 00:00:00”,“entries”:{“dateTime”:“2016-09-13 00:00:00:00”,“speed”:9.1,“direction”:287,“directionText”:“WNWW”;“dateTime”:“2016-09-13 01:00:00:00”,“speed”:9.3,“directionText”:“Direction258”“:“WSW”},{“日期时间”:“2016-09-13 02:00:00”,“速度”:9.3,“方向”:256,“方向文字”:“WSW”},{“日期时间”:“2016-09-13 03:00:00”,“速度”:9.1,“方向”:254,“方向文字”:“WSW”},{“日期时间”:“2016-09-13 04:00:00”,“速度”:6.9,“方向”:260,“方向文字”:“W”},{“日期时间”:“2016-09-13 05:00:00”,“速度”:5.7,“方向”:256,“方向文字”:{“日期时间”:“2016-09-13 06:00:00”,“速度”:5.7,“方向”:249,“方向文本”:“WSW”},{“日期时间”:“2016-09-13 07:00:00”,“速度”:5.9,“方向”:245,“方向文本”:“WSW”},{“日期时间”:“2016-09-13 08:00:00”,“速度”:5.2,“方向”:254,“方向文本”:“WSW”},{“日期时间”:“2016-09-13 09:00:00”,“速度”:4.6,“方向”:2722016-09-13 10:00:00,“速度”:4.6,“方向”:281,“方向文本”:“W”},{“日期时间”:“2016-09-13 11:00:00”,“速度”:6.1,“方向”:312,“方向文本”:“NW”},{“日期时间”:“2016-09-13 12:00:00”,“速度”:8,“方向”:14,“方向文本”:“NNE”},{“日期时间”:“2016-09-13 13 13 13:00:00:00”,“速度”:9.6,“方向”:45,“方向文本”:“NE”{“日期时间”:2016-09-13 14:00:00,“速度”:9.8,“方向”:56,“方向”:88,“方向”:E“},{”dateTime“:“2016-09-13 15:00:00”,“速度”:9.6,“方向”:77,“方向”text“:“ENE”},{”dateTime“:“2016-09-13 16:00:00”,“速度”:9.4,“方向”:88,“方向”:E“},{”dateTime“:“2016-09-13 17:00:00”,“速度”:10.7,“方向”:73,“方向:”dateTime“:“ENE2016-09-13 18:00:00,“速度”:11.9,“方向”:43,“方向”:11,“方向”:11,“方向”:11,“方向”文本:“N”},“日期”:12.6,“方向”:28,“方向”:文本:“NNE”},{“日期”:2016-09-13 20:00:00,“速度”:11.7,“方向”:11,“方向:”文本:“N”},{“日期”:“2016-09-13 21:00:00”,“速度”:9.8,“方向”:336,“方向”:文本:“NNW”},{“日期”:2016-09-13 22:00:00,“速度”:7.8,“方向”:318,“方向文本”:“NW”},{“日期时间”:“2016-09-13 23:00:00”,“速度”:4.6,“方向”:304,“方向文本”:“NW”}],“单位”:“{“速度”:“km/h”}”,发布时间::“2016-09-13 12:11:55”},“预报图”:“{”温度“{”数据配置“{”系列“{”配置“{”id:“温度”、“颜色”;“3552”;“线宽”lineFill“:false,“lineRenderer“:”StraightLineRenderer“,”showPoints“:false“,”pointFormatter“:”TemperaturePointFormatter“,”yAxisDataMin“:10.7,“yAxisDataMax“:22.2,“yAxisMin”:0,“yAxisMax”:32,“Group:”[{“dateTime”:1473724800,“points”:“:”:”:[{“x”:1473724800,“y”:12.4},{“x”:1473728400,“y”:11.7},{“x”:11.3},{“x”:14739200,“y”:10.9 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7,y:11 7 7 7 7 7,{“x”:147375万万,y:12.2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7万,y:11 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7万,y:7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7万,7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7,7 7{“x”:1473782400,“y”:20.7},{“x”:1473786000,“y”:19.1},{“x”1473789600,“y”:1473789600,1473789600,“y”:1473789600,“y”:17.6},,{“x”:1473789600,y:15.3},{“x”:1473789600,y:1473789600,y:1473789600,y:1473789600,y:17.6},{“x”:1473737939393200,y:14737373796800,“y”:15.3},y:15.3.3},,,,,,,,,,3.3.3},,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,控制点:,,,,,,,,,,,,,,,,,,,,控制点::::2016-09-13 07:21:53“,“nextIssueDateTime”:“2016-09-13 08:21:53”},“precis”:{“dataConfig”:{“series”:{“config”:{“id”:“precis”,“lineFill”:false,“showPoints”:true,“pointRenderer”:“PrecisumaryPointRenderer”,“pointFormatter”:“PrecisumaryPointFormatter”},“Group”:[{“dateTime”:1473724800,“points”:[{“x”:1473728400,“precisCode”:“部分多云”,“夜间”:true},{“x”:1473739200,“精度码”:“雾”、“夜”:真},{“x”:1473750000,“精度码”:“多云”、“夜”:假},{“x”:1473760800,“精度码”:“多云”、“夜”:假},{“x”:1473771600,“精度码”:“多云”、“夜”:假},{“x”:1473782400,“精度码”:“多云”、“夜”:假},{“x”:1473793200,“精度码”:“偶然阵雨云”、“夜”:真},{“x”“:1473804000,“精度代码”:“阵雨”、“夜晚”:真实}],“控制点”:[]},“Xaximin”:1473724800,“Xaximax”:1473811199}}},,“观测”:{“观测”:{“温度”:{“温度”:18.5,“表观温度”:17.4,“趋势”:-1},“湿度”:{“百分比”:87},“露点”:{“温度”:16.3,“趋势”:1},“压力”:{“趋势”:1019.3,“趋势”:零},”,“风”:{“速度”:16.7,“阵风速度”:20.4,“趋势”:0,“方向”:202.5,“方向文字”:“SSW”},“降雨”:{“最后一个小时山”:0,“todayAmount”:0,“自9amamount”:0},{“温度”:{“名称”:“诺拉头AWS”,“距离”:15.5},“压力”:{“名称”:“诺拉头AWS”,“距离”:15.5},“风”:{“名称”:“诺拉头AWS”,“距离”:15.5},“降雨”:Norah Head AWS,distance:15.5},issueDateTime:“2016-09-13 12:20:00”,“单位:{“温度”:“c”,“数量”:“mm”,“速度”:“km/h”,“距离”:“km”,“压力”:“hPa”},”,“观测图”:{“压力”:{“数据配置”:{“系列”:{“配置”:{“id”:“压力”,“颜色”:“003355”,“线宽”:2,“线填充”:假,“线渲染器”:“Stra”:
Sub jsonDecode()

 Dim jsonDecode As Variant
 jsonText = Worksheets("Sheet3").Range("A1").Value
 Set sc = CreateObject("ScriptControl"): sc.Language = "JScript"

 sc.AddCode "function getProperty(jsonObj, propertyName) { return jsonObj[propertyName]; } "

 Set jsonDecode = sc.Eval("(" + jsonText + ")")

 Set oLocation = sc.Run("getProperty", jsonDecode, "location")
 MsgBox sc.Run("getProperty", oLocation, "id")

 Set oForecasts = sc.Run("getProperty", jsonDecode, "forecasts")
 Set oWeather = sc.Run("getProperty", oForecasts, "weather")
 Set oDays = sc.Run("getProperty", oWeather, "days")
 Set oDay0 = sc.Run("getProperty", oDays, "0")
 MsgBox sc.Run("getProperty", oDay0, "dateTime")

End Sub