Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: cant access from JSON.Net object properties, items

$
0
0
Hi again,

There are several issues with the above. The JSON sample isn't proper JSON, and the code sample (assuming it's JavaScript) seems to have at least one typo and is unlikely to work unless Json is a reference to a custom object of some kind.

Please refer to the working sample below, which uses the console for output (since we're not sure what $alert is):
engine.AddHostType(typeof(Console));
engine.Script.result = "[{\"content\": \"hello world\"}]";
engine.Execute(@"
    var j = JSON.parse(result);
    Console.WriteLine(j[0].content);
");
This sample writes "hello world" to the console. Note that if you're using JScript, you'll need WindowsScriptEngineFlags.EnableStandardsMode to enable the standard JSON object.

Good luck!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>