我有嵌套集合,我添加“数据”然后预先“数据”我添加自己的“标签”。我发现“数据”与“标签”的foreach一起放松。 我想添加我手动从集合外部导入信息的人。
我在Cypher查询语句下面执行: 我模仿了: Cypher Import Statement 和 Cypher Unwind 我通过enter link description here检查了我的json并且它已经过验证。
{ "statements": [ { "statement": " WITH { "categories": [ {"dataid" : "11" , "dataname" : "data1" , "datalanguage" : "en" , "datatype" : "type1" ,"content" : "content1" , "tags" : [{"myid" : "11" , "tagid" : 10 , "tagname" : "tag1" }] } , {"dataid" : "22" , "dataname" : "data2" , "datalanguage" : "en" , "datatype" : "type2" ,"content" : "content2" , "tags" : [{"myid" : "22" , "tagid" : 20 , "tagname" : "tag2" }] } ] } AS document UNWIND document.categories AS category MERGE (dt:Data {name: category.dataname}) ON CREATE SET dt.id = category.dataid , dt.type = category.datatype , dt.language = category.datalanguage , dt.content = category.datacontent MERGE (p:Person { name : 'Mahsa' , lastname : 'Mahsa' } ) ON CREATE SET p.id =1 MERGE (p)-[r:owner]->(dt) FOREACH (mytag IN category.tags | MERGE (t:Tag {name: mytag.tagname}) ON CREATE SET t.id = mytag.tagid MERGE (dt)-[r2:tagged { Freq : 12 ]->(t) )" } ] }
但它返回结果:(我多次检查“意外的字符”但我找不到)
{"results":[],"errors":[{"code":"**Neo.ClientError.Request.InvalidFormat**","message":"**Unable to deserialize request: Unexpected character ('c' (code 99)): was expecting comma to separate OBJECT entries**\n at [Source: HttpInputOverHTTP@132e16b; line: 1, column: 48]"}]}
我将嵌套集合设为:
string dataCollection2 = "{ \"categories\": [ {\"dataid\" : \"11\" , \"dataname\" : \"data1\" , \"datalanguage\" : \"en\" , \"datatype\" : \"type1\" ," +
"\"content\" : \"content1\" , \"tags\" : [{\"myid\" : \"11\" , \"tagid\" : 10 , \"tagname\" : \"tag1\" }] }" +
" , {\"dataid\" : \"22\" , \"dataname\" : \"data2\" , \"datalanguage\" : \"en\" , \"datatype\" : \"type2\" ," +
"\"content\" : \"content2\" , \"tags\" : [{\"myid\" : \"22\" , \"tagid\" : 20 , \"tagname\" : \"tag2\" }] } ] }";
var obj1 = JValue.Parse(@"'" + dataCollection2 + "'");
我将我的json导入http://jsonlint,com,我得到了验证:
{
"categories": [
{
"dataid": 11,
"dataname": "data1",
"datalanguage": "en",
"datatype": "type1",
"content": "content1",
"tags": [
{
"myid": 11,
"tagid": 10,
"tagname": "tag1"
}
]
},
{
"dataid": 22,
"dataname": "data2",
"datalanguage": "en",
"datatype": "type2",
"content": "content2",
"tags": [
{
"myid": 22,
"tagid": 20,
"tagname": "tag2"
}
]
}
]}
答案 0 :(得分:2)
您传递给REST API的字符串的基本问题是您没有传递合法的Cypher查询。 Cypher属性“maps”看起来有点像JSON,不是JSON。
在您的情况下,重要的区别是属性名称不能用双引号分隔。只有字符串属性值可以用双引号分隔。
因此,categories
,dataId
,dataName
等不得用双引号括起来。
在查询结尾附近也有拼写错误。 [r2:tagged { Freq : 12 ]
应为[r2:tagged { Freq : 12} ]
。
答案 1 :(得分:0)
用于将嵌套集合添加到neo4j:
首先:为了正确输入neo4j作为参数我必须删除" { "类别":[]}"从json的第一个和最后一个开始。
其次:我应该将此json作为参数添加到语句
中第三:我必须使用两个" UNWIND和WITH" (而不是使用foreach)将父级或子级的每一行与集合分开。
" FOREACH"类似于" UNWIND和WITH"。 我的最终收藏和查询是:
<强>收集:强>
{"id" : 1, "name" : "Data1", "language" : "en", "tags": {"id" : 11, "name": "tag 11" } } , {"id" : 2, "name": "Data2" , "tags": [ {"id" : 33, "name": "tag 33"} , {"id" : 44, "name": "tag44"} ] }
<强>查询:强>
{ "statements": [ { "statement": " UNWIND { datas } AS data MERGE (p:Person { name : 'God' , lastname : 'God' } ) ON CREATE SET p.id =2 MERGE (d:Data {name: data.name}) ON CREATE SET d.id = data.id , d.language = data.language MERGE (p)-[r:owner]->(d) WITH d, data.tags AS mytags UNWIND mytags AS mytag MERGE (t:Tag {name: mytag.name}) ON CREATE SET t.id = mytag.id MERGE (d)-[r2:tagged { Freq : 12 } ]->(t) " , "parameters": { "datas" : [{"id" : 1, "name" : "Data1", "language" : "en", "tags": {"id" : 11, "name": "tag 11" } } , {"id" : 2, "name": "Data2" , "tags": [ {"id" : 33, "name": "tag 33"} , {"id" : 44, "name": "tag44"} ] }] } } ] }