我正在研究json数据。我将csv文件转换为json,当我尝试通过不同的json验证器站点验证该数据时,我得到以下错误:
JSON字符串有效,但JSON数据不准确
我的数据如下:
[{
"also_item": "item3",
"unit_count": "1",
"driver": "item3",
"rank": "1"
}][{
"also_item": "item4",
"unit_count": "1",
"driver": "item4",
"rank": "1"
}][{
"also_item": "item5",
"unit_count": "1",
"driver": "item5",
"rank": "1"
}][{
"also_item": "item6",
"unit_count": "1",
"driver": "item6",
"rank": "1"
}][{
"also_item": "item7",
"unit_count": "1",
"driver": "item7",
"rank": "1"
}][{
"also_item": "item8",
"unit_count": "1",
"driver": "item8",
"rank": "1"
}][{
"also_item": "item9",
"unit_count": "1",
"driver": "item9",
"rank": "1"
}][{
"also_item": "item20",
"unit_count": "1",
"driver": "item20",
"rank": "1"
}][{
"also_item": "item21",
"unit_count": "1",
"driver": "item21",
"rank": "1"
}][{
"also_item": "item22",
"unit_count": "1",
"driver": "item22",
"rank": "1"
}][{
"also_item": "item10",
"unit_count": "1",
"driver": "item10",
"rank": "1"
}][{
"also_item": "item11",
"unit_count": "1",
"driver": "item11",
"rank": "1"
}][{
"also_item": "item12",
"unit_count": "1",
"driver": "item12",
"rank": "1"
}][{
"also_item": "item13",
"unit_count": "1",
"driver": "item13",
"rank": "1"
}][{
"also_item": "item14",
"unit_count": "1",
"driver": "item14",
"rank": "1"
}][{
"also_item": "item15",
"unit_count": "1",
"driver": "item15",
"rank": "1"
}][{
"also_item": "item16",
"unit_count": "1",
"driver": "item16",
"rank": "1"
}][{
"also_item": "item17",
"unit_count": "1",
"driver": "item17",
"rank": "1"
}][{
"also_item": "item18",
"unit_count": "1",
"driver": "item18",
"rank": "1"
}][{
"also_item": "item",
"unit_count": "1",
"driver": "item",
"rank": "1"
}, {
"also_item": "item19",
"unit_count": "1",
"driver": "item19",
"rank": "1"
}][{
"also_item": "item1",
"unit_count": "1",
"driver": "item1",
"rank": "1"
}][{
"also_item": "item2",
"unit_count": "1",
"driver": "item2",
"rank": "1"
}][{
"also_item": "item3",
"unit_count": "1",
"driver": "item3",
"rank": "1"
}][{
"also_item": "item4",
"unit_count": "1",
"driver": "item4",
"rank": "1"
}][{
"also_item": "item5",
"unit_count": "1",
"driver": "item5",
"rank": "1"
}][{
"also_item": "item6",
"unit_count": "1",
"driver": "item6",
"rank": "1"
}][{
"also_item": "item7",
"unit_count": "1",
"driver": "item7",
"rank": "1"
}][{
"also_item": "item8",
"unit_count": "1",
"driver": "item8",
"rank": "1"
}][{
"also_item": "item9",
"unit_count": "1",
"driver": "item9",
"rank": "1"
}][{
"also_item": "item20",
"unit_count": "1",
"driver": "item20",
"rank": "1"
}][{
"also_item": "item21",
"unit_count": "1",
"driver": "item21",
"rank": "1"
}][{
"also_item": "item22",
"unit_count": "1",
"driver": "item22",
"rank": "1"
}]
我正在使用this进行验证。 任何人都可以告诉我的json数据应该是什么样子或它是什么类型的错误。
答案 0 :(得分:1)
错误似乎在条目之间:
}][{
你需要在它们之间加上逗号:
}],[{
你也不应该只有一个对象的数组,数组应该包围整个JSON
这是你固定的JSON:
[
{
"also_item": "item3",
"unit_count": "1",
"driver": "item3",
"rank": "1"
},
{
"also_item": "item4",
"unit_count": "1",
"driver": "item4",
"rank": "1"
},
{
"also_item": "item5",
"unit_count": "1",
"driver": "item5",
"rank": "1"
},
{
"also_item": "item6",
"unit_count": "1",
"driver": "item6",
"rank": "1"
},
{
"also_item": "item7",
"unit_count": "1",
"driver": "item7",
"rank": "1"
},
{
"also_item": "item8",
"unit_count": "1",
"driver": "item8",
"rank": "1"
},
{
"also_item": "item9",
"unit_count": "1",
"driver": "item9",
"rank": "1"
},
{
"also_item": "item20",
"unit_count": "1",
"driver": "item20",
"rank": "1"
},
{
"also_item": "item21",
"unit_count": "1",
"driver": "item21",
"rank": "1"
},
{
"also_item": "item22",
"unit_count": "1",
"driver": "item22",
"rank": "1"
},
{
"also_item": "item10",
"unit_count": "1",
"driver": "item10",
"rank": "1"
},
{
"also_item": "item11",
"unit_count": "1",
"driver": "item11",
"rank": "1"
},
{
"also_item": "item12",
"unit_count": "1",
"driver": "item12",
"rank": "1"
},
{
"also_item": "item13",
"unit_count": "1",
"driver": "item13",
"rank": "1"
},
{
"also_item": "item14",
"unit_count": "1",
"driver": "item14",
"rank": "1"
},
{
"also_item": "item15",
"unit_count": "1",
"driver": "item15",
"rank": "1"
},
{
"also_item": "item16",
"unit_count": "1",
"driver": "item16",
"rank": "1"
},
{
"also_item": "item17",
"unit_count": "1",
"driver": "item17",
"rank": "1"
},
{
"also_item": "item18",
"unit_count": "1",
"driver": "item18",
"rank": "1"
},
{
"also_item": "item",
"unit_count": "1",
"driver": "item",
"rank": "1"
},
{
"also_item": "item19",
"unit_count": "1",
"driver": "item19",
"rank": "1"
},
{
"also_item": "item1",
"unit_count": "1",
"driver": "item1",
"rank": "1"
},
{
"also_item": "item2",
"unit_count": "1",
"driver": "item2",
"rank": "1"
},
{
"also_item": "item3",
"unit_count": "1",
"driver": "item3",
"rank": "1"
},
{
"also_item": "item4",
"unit_count": "1",
"driver": "item4",
"rank": "1"
},
{
"also_item": "item5",
"unit_count": "1",
"driver": "item5",
"rank": "1"
}][{
"also_item": "item6",
"unit_count": "1",
"driver": "item6",
"rank": "1"
},
{
"also_item": "item7",
"unit_count": "1",
"driver": "item7",
"rank": "1"
},
{
"also_item": "item8",
"unit_count": "1",
"driver": "item8",
"rank": "1"
},
{
"also_item": "item9",
"unit_count": "1",
"driver": "item9",
"rank": "1"
},
{
"also_item": "item20",
"unit_count": "1",
"driver": "item20",
"rank": "1"
},
{
"also_item": "item21",
"unit_count": "1",
"driver": "item21",
"rank": "1"
},
{
"also_item": "item22",
"unit_count": "1",
"driver": "item22",
"rank": "1"
}
]
答案 1 :(得分:1)
这不是一个有效的JSON。
如果您将JSON粘贴到http://www.jsoneditoronline.org/之类的内容中,您应该会看到问题。
结构并不好。 它应该是一个对象数组:
[
{
"also_item": "item3",
"unit_count": "1",
"driver": "item3",
"rank": "1"
},
{
"also_item": "item4",
"unit_count": "1",
"driver": "item4",
"rank": "1"
}
]
修改强>
@Downgoat位于右侧,但您必须将整个结果包装在数组[]
中。然后它会起作用,但我认为你应该解决这个问题。拥有许多包含一个对象的数组并不好。你应该有1个包含许多对象的数组。
答案 2 :(得分:0)
JSON无效,因为您有多个根元素。您需要转换类似于以下示例。你有额外的"] ["例如,在item3和item4之间。删除","它会起作用。对所有其他人重复同样的事情。
tview.dataSource = self