Json support

Nov 12, 2009 at 11:11 PM

Hi 

Is is possible to evaluate json expressions using jint?

For example, the following code should return February when executed:

 

var list = eval([{'Key':'Select Month','Value':''},{'Key':'January','Value':'0'},{'Key':'February','Value':'1'},{'Key':'March','Value':'2'},
{'Key':'April','Value':'3'},{'Key':'May','Value':'4'},{'Key':'June','Value':'5'},{'Key':'July','Value':'6'},{'Key':'August','Value':'7'},
{'Key':'September','Value':'8'},{'Key':'October','Value':'9'},{'Key':'November','Value':'10'},{'Key':'December','Value':'11'}]);
alert(list[2].Key);

var list = eval([{'Key':'Select Month','Value':''},{'Key':'January','Value':'0'},{'Key':'February','Value':'1'},{'Key':'March','Value':'2'},{'Key':'April','Value':'3'},{'Key':'May','Value':'4'},{'Key':'June','Value':'5'},{'Key':'July','Value':'6'},{'Key':'August','Value':'7'},{'Key':'September','Value':'8'},{'Key':'October','Value':'9'},{'Key':'November','Value':'10'},{'Key':'December','Value':'11'}]); return list[2].Key;

Thanks

Rob

 

Nov 13, 2009 at 12:57 AM

I've had a lot of good luck with JsonFX's JSON library:  http://jsonfx.net/download/  (The one I use has some custom tweaks)

You can use it to get a Dictionary<string, object> from JSON.