我有一个自定义平台,我上传文件。平台获取文件的内容(映射),然后我有一个屏幕,我可以看到内容。
我的问题是使用特定的JSON文件。这是原始格式:
{"schema:actor:image":"https://LINK.png","schema:activity.timestamp:timestamp":"01/06/2016 19:23:01","schema:metadata:datatype":"text","schema:actor:name":"AAAA","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE1","schema:activity.content:language":["english"],"schema:activity.location:placename":"City of London, United Kingdom","schema:actor:followers_count":1518,"schema:activity.content:sentiment":"positive","schema:activity.content:opinion":"neutral","schema:activity.content:gender":"unknown","schema:activity.content:age":"35-49","schema:actor:synthetic":"no","schema:activity:original_post":null,"streams":["Apollo"]} {"schema:actor:image":"https://LINK2.jpg","schema:activity.timestamp:timestamp":"02/06/2016 23:16:39","schema:metadata:datatype":"text","schema:actor:name":"BBBB","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE2","schema:activity.content:language":["english"],"schema:activity.location:placename":"Birmingham, United Kingdom","schema:actor:followers_count":28,"schema:activity.content:sentiment":"neutral","schema:activity.content:opinion":"subjective","schema:activity.content:gender":"unknown","schema:activity.content:age":"25-34","schema:actor:synthetic":"no","schema:activity:original_post":"738022479273454944","streams":["Apollo"]}
我无法在平台上使用此文件。使其工作的唯一方法是稍微改变格式。这种格式有效:
[{"schema:actor:image":"https://LINK.png","schema:activity.timestamp:timestamp":"01/06/2016 19:23:01","schema:metadata:datatype":"text","schema:actor:name":"AAAA","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE1","schema:activity.content:language":["english"],"schema:activity.location:placename":"City of London, United Kingdom","schema:actor:followers_count":1518,"schema:activity.content:sentiment":"positive","schema:activity.content:opinion":"neutral","schema:activity.content:gender":"unknown","schema:activity.content:age":"35-49","schema:actor:synthetic":"no","schema:activity:original_post":null,"streams":["Apollo"]},
{"schema:actor:image":"https://LINK2.jpg","schema:activity.timestamp:timestamp":"02/06/2016 23:16:39","schema:metadata:datatype":"text","schema:actor:name":"BBBB","schema:metadata.tags:key":null,"schema:activity.content:value":"VALUE2","schema:activity.content:language":["english"],"schema:activity.location:placename":"Birmingham, United Kingdom","schema:actor:followers_count":28,"schema:activity.content:sentiment":"neutral","schema:activity.content:opinion":"subjective","schema:activity.content:gender":"unknown","schema:activity.content:age":"25-34","schema:actor:synthetic":"no","schema:activity:original_post":"738022479273454944","streams":["Apollo"]}]
图片中的差异在这里(添加为红色):
有没有办法使用JSONpath读取第一个文件?我不熟悉JSONpath,我无法读取第一个文件。
或者,我正在考虑操作文件以添加缺少的部分 - >使它看起来像第二个文件。
答案 0 :(得分:2)
你的第一个JSON的问题是你传递了几个以逗号分隔的对象{},但是你没有包含在另一个对象或数组[]中。
{},{},{} === bad formed JSON, three orphan objects
{ "obj1": {}, "obj2": {}, "obj3": {} } === good JSON, one object that encloses three other objects into it's attributes
[ {}, {}, {} ] === good JSON, an array of JSON objects.