How i can add a List to the JSON POST request with webwrite (required for RESTful interface of Neo4j)
3 次查看(过去 30 天)
显示 更早的评论
The following RESTful JSON Interface is needed to submit a Query (e.g. Node creation) to a Neo4j-Database:
{
"statements" : [ {
"statement" : "CREATE (n) RETURN id(n)"
} ]
}
The JSON-Object is created internal the WEBWRITE-Function. The nested structure can be created in Matlab and is compiled to JSON by the WEBWRITE-Function as well. I was unable to create a JSON List (Array) by using the following approach (Cell Array):
api = 'http://localhost:7474/';
url = [api 'db/data/transaction/commit'];
statem{1,1} = 1;
ab = struct('statement', 'CREATE (n) RETURN id(n)');
statem{1,1} = ab;
statems = struct('statements', statem);
options = weboptions('ContentType','json', 'MediaType','application/json', 'RequestMethod','POST', 'Username', 'neo4j', 'Password', 'test');
data = webwrite(url, statems, options);
JSON-Result created by the function above:
{
"statements": {
"statement": "CREATE (n) RETURN id(n)"
}
}
Is there a way to create a List in the JSON-Object created by WEBWRITE?
0 个评论
采纳的回答
Robert Snoeberger
2015-12-15
编辑:Robert Snoeberger
2015-12-15
To create a JSON Array, you should use a cell array. However, you should be careful when passing a cell array as a value input argument to the function struct [1]. There are a few ways to proceed.
You could avoid the struct function when building the "statements" name-value pair:
>> ab = struct('statement', 'CREATE (n) RETURN id(n)');
>> statems.statements = {ab}
statems =
statements: {[1x1 struct]}
>>
You could add an extra pair of curly braces '{}' when the value input argument to struct is a cell array:
>> ab = struct('statement', 'CREATE (n) RETURN id(n)');
>> statems = struct('statements', {{ab}})
statems =
statements: {[1x1 struct]}
>>
Just make sure that the display of the variable statems includes a pair of curly braces '{}' around [1x1 struct]:
statems =
statements: {[1x1 struct]}
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 JSON Format 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!