cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Json object in propertys

Hello,
I want to put a json object into a property and retrive it.
Ex: i have a node with a property test:'[{"id":"string",tilte:"string"},{"id":"string",tilte:"string"}]'
i want to deserialize this property ton an object with de neojclient driver but this property is always null.

Any ideas ?

thanks
thierry

1 REPLY 1

mdfrenchman
Graph Voyager
using (var session = Global.Neo4jDriver.Session())
 {
   // Quick and dirty example, don't recommend ever using session.Run.First.
   var record = session.Run("MATCH (t:TestJson) RETURN t.test").First();
   var type = record[0].GetType();
   var value = record[0];
}

Give's you the result of:
?value
"[{\"id\":\"string\",tilte:\"string\"},{\"id\":\"string\",tilte:\"string\"}]"
?type
{Name = "String" FullName = "System.String"}

So there's a few ways to deserialize that.
ref: JSON Serialization and Deserialization in C#

I went with the non JSON.Net one because I didn't need to mess with nuget.

using (var session = Global.Neo4jDriver.Session())
{
  var record = session.Run("MATCH (t:TestJson) RETURN t.test").First();
  var type = record[0].GetType();
  string value = record[0].As<string>();
  var js = new System.Web.Script.Serialization.JavaScriptSerializer();
  var testObjs = js.Deserialize<dynamic>(value);
}