我想根据从json文件读取的数据创建Neo4j图,但是我无法循环获得的数据。
我试图按照以下示例进行操作: https://neo4j.com/blog/cypher-load-json-from-url/
但是,我的apoc.load.json结果的结构似乎并不相似。我试图弄清楚我可以代替什么:
UNWIND data.items as q
在示例中,对于我来说,这是行不通的。
要了解输出的结构,我在Neo4j浏览器中执行了此操作:
CALL apoc.load.json('mytest.json') YIELD value
RETURN keys(value)
结果:
["favorites", "sentiment", "content-length", "keywords", "published-at", "reach", "title", "facts", "posts", "normalized-flesch-score", "ext-url", "shares", "last-modified", "score", "xscore", "companies", "quote", "provider", "content-type", "created-at", "categories", "id", "lang", "value", "keyphrases", "annotation", "duplicates", "karma", "topics", "subjects", "al", "possibly-sensitive", "inserted-at", "tags", "replies", "entities", "meta", "domain", "flesch-score", "locations", "parent-id", "relations", "adult", "non-media-entities", "user", "tr", "status"]
["favorites", "sentiment", "content-length", "keywords", "published-at", "reach", "title", "facts", "posts", "normalized-flesch-score", "ext-url", "shares", "last-modified", "score", "xscore", "companies", "quote", "provider", "content-type", "created-at", "categories", "id", "lang", "value", "keyphrases", "annotation", "duplicates", "karma", "topics", "subjects", "al", "possibly-sensitive", "inserted-at", "tags", "replies", "entities", "meta", "domain", "flesch-score", "locations", "parent-id", "relations", "adult", "non-media-entities", "user", "tr", "status"]
...
但是,当我尝试遍历输出中的对象并返回这样的一个键时:
CALL apoc.load.json('mytest.json') YIELD value
UNWIND value AS v
RETURN v.favorites
我得到一个错误:
Neo.ClientError.Statement.SyntaxError: Type mismatch: expected List<T> but was Map (line 2, column 8 (offset: 62))
"UNWIND value AS v"
^
另一方面,如果我遍历实例value.title而不是value,则会得到有意义的值。
然后,我看了一些用cypher循环遍历地图的示例,但这些地图显示那里的结构都不同,并且解决方案(至少对于初学者而言)不适用于我的问题。
如果有人可以给我一些有关如何遍历我所拥有的对象的信息,那将是很好的。提前非常感谢!
答案 0 :(得分:0)
您无需在此处使用unwind
。
您可以简单地将收藏夹返回为:
CALL apoc.load.json('mytest.json') YIELD value
RETURN value.favorites
答案 1 :(得分:0)
original_state
返回的每个updated_orders
都是map,而不是列表。
要从地图上获取任何属性(例如value
)的值,只需使用apoc.load.json
(或foo
)。例如:
value.foo