I have an array of JSON objects, some of which contain key/value pairs for which the value is an array.
Example:
var jsonArray = [{ "key1":"value1", "key2":["value21", "value22"]},
{ "key1":"value3", "key2":["value41", "value42"]}];
EDIT: Accidentally used braces instead of brackets.
I am trying to send this via AJAX to an ASP.NET web service using jQuery:
$.ajax({
type: "post",
url: "example.asmx/SomeFunction"
data: "{ 'items': '" + JSON.stringify(jsonArray) + "' }",
contentType: "application/json;charset=utf-8",
dataType: "json"
});
Is this the correct way to send the data? Also, what data type do I need in the SomeFunction parameter to accept and parse the JSON data?
No, the following would be better:
It would map to:
where
Foois defined like this:In my example I’ve used
IEnumerable<T>as I assume you would be only enumerating over the values but if you need indexer you could also define them as arraysT[].