This project has moved. For the latest updates, please go here.

Simple name/value deserialize

Feb 15, 2012 at 11:58 AM


I'm trying to get the name/value pairs with this code (csharp code embedded in a GeneXus object): 


&jsonString = '{"key1":"value1","key2":"value2"}'
&nombre = ''
&valor = ''
csharp Newtonsoft.Json.Linq.JObject jsonObj = new Newtonsoft.Json.Linq.JObject();
csharp jsonObj = Newtonsoft.Json.Linq.JObject.Parse([!&jsonString!]);
csharp System.Collections.Generic.IList propertyNames = jsonObj.Properties().Select(p => p.Name).ToList();
csharp foreach (string jkey in propertyNames)
csharp {
csharp [!&nombre!] = jkey;
csharp [!&valor!] = jsonObj[jkey];
//other genexus statements
csharp }

Is this the best way to do it?
If the string contains a collection, how I can handle that?

Thanks in advance for any suggestions! (apologies for my english)

Miguel (.Net newbie)