javascript - C#: how to get all values for keys from JS Object? -
i have c# application in web page. web calls apllication via js:
var info = {key1:value1, key2:value2}; app["methodname"](data);
so, in app:
public void methodname(object data) { //need here this: foreach (var key in data) { var value = data[key]; } }
the newtonsoft.json library lets parse arbitrary json dynamic object so:
using newtonsoft.json.linq; ... dynamic obj = jobject.parse("{\"key1\":\"value1\", \"key2\":\"value2\"}"); console.writeline(obj.key1); console.writeline(obj.key2);
the equivalent of method provided in post similar this:
public static void methodname(dynamic data) { foreach (var keyvaluepair in data) { var value = keyvaluepair.value; console.writeline(keyvaluepair.name + ": " + keyvaluepair.value); } }
javascript c#
No comments:
Post a Comment