I have a C# application in web page. Web calls my apllication via JS:
var data = {key1:value1, key2:value2};
app["methodName"](data);
So, in my app:
public void methodName(object data)
{
//need here something like this:
foreach (var key in data)
{
var value = data[key];
}
}
The Newtonsoft.JSON library lets you parse arbitrary JSON into a dynamic object like so:
using Newtonsoft.Json.Linq;
...
dynamic obj = JObject.Parse("{\"key1\":\"value1\", \"key2\":\"value2\"}");
Console.WriteLine(obj.key1);
Console.WriteLine(obj.key2);
The equivalent of the method you provided in your post would be similar to this:
public static void methodName(dynamic data)
{
foreach (var keyValuePair in data)
{
var value = keyValuePair.Value;
Console.WriteLine(keyValuePair.Name + ": " + keyValuePair.Value);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments