I'm trying to send JSON array from javascript to c# but I always get errors on deserializing. First I tried to serialize the normal js array JSON.stringify(order)
but on c# I get
Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'Order[]' because the type requires a JSON array (eg [1,2,3]) to deserialize correctly.
Order[] order = JsonConvert.DeserializeObject<Order[]>(json); //this is line with error
After that I tried to convert js array to object and after that serialize to json
function toObject(arr) {
var rv = {};
for (var i = 0; i < arr.length; ++i)
rv[i] = arr[i];
return rv;
}
{"0":["Item1","2"],"1":["Item2","1"]} //JSON
That is how JSON looks like now, but again same error.
Look at JsonConvert.DeserializeObject it is a Newtonsoft library.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.