json - ASPjson 中的嵌套数组
问题描述
使用https://www.aspjson.com/解析写入 JSON
我有一个组织的数据结构。这些信息之一是他们的物理位置。每个位置可以有多个房间。但是,当我尝试编写代码以在每个位置项中创建房间时,我收到一个错误:Object required: 'JSON.data(...)
.
这是我迄今为止成功编写的代码:
{
"locations": [{
"locationid": 524,
"locationname": "test building"
},
{
"locationid": 525,
"locationname": " building 1"
},
{
"locationid": 526,
"locationname": "test building 2"
},
{
"locationid": 527,
"locationname": "test building 3"
},
]
}
我想做的是在每个位置项中创建一个“房间”集合,就像下面这样,但是在尝试创建第二个嵌套房间数组时出现上述错误。(见下面我的代码)
{
"locationid": 527,
"locationname": "test building 3",
"rooms" :[
{
"roomid": 111,
"roomname": "room 1 "
},
{
"roomid": 222,
"roomname": "room 2"
},
]
},
// additional locations follow ...
我当前的代码:
.Add "locations", JSON.Collection()
With JSON.data("locations")
.Add 0, JSON.Collection()
With .item(0)
.Add "locationid", 111
.Add "locationname", "location 1"
.Add "rooms", JSON.Collection()
With JSON.data("rooms") /// this is where I get the error.
.Add 0, JSON.Collection()
With .item(0)
.Add "roomid", 1
.Add "roomname", "room1"
end with
.Add 1, JSON.Collection()
With .item(1)
.Add "roomid", 2
.Add "roomname", "room2"
end with
end with
end with
end with
解决方案
您需要遵循的对象的结构JSON.data("rooms")
将不存在,因为JSON.data()
是从 JSON 结构的根读取。添加rooms
集合后,您需要从该实例开始工作,因为当前.Item
实例是添加集合的上下文rooms
。所以这条线应该是;
With .Item("rooms")
推荐阅读
- excel - 无法将发送键值发送到特定 CELLS
- c# - 如果不存在,则插入 ELSE UPDATE SQL
- python - Dockerized Django 应用程序未应用唯一约束
- javascript - 弹出窗口不会显示按钮操作
- javascript - 如何在网络主机中访问我的后端 API?
- python-3.x - 如何使用带有补丁矩形的艺术家同时移动 2 个矩形
- c - gtk+加速组回调函数问题
- python - 每小时检查外部网站上是否存在特定的 html 类
- google-sheets - 使用一个方程式导入一个巨大的范围还是为特定列导入较小的范围更可取?
- r - 绘制带有两个标签的顶点,一个在顶点内部,另一个在顶点外部