How to get array data from json in c#?
Here is the ajax code
$.ajax({
type: "GET",
url: "/Weather/GetWeather",
data: { "a": ["1,","2&"], "b" : 4 },
success: onScc,
error: onErr,
dataType: "json"
});
The ajax above will invoke method named GetWeather in Asp.net MVC.
public string GetWeather()
{
//Request.QueryString.ToString() ---> a%5b%5d=1%2c&a%5b%5d=2%26&b=4
string a = HttpUtility.UrlDecode(Request.QueryString.ToString());
// string a ---> a=1,&a=2&&b=4
.....
}
what I got from .net is —–> a[]=1,&a[]=2&&b=4
what I want to get is like —-> string[]a = ["1", "2&"] and int b = 4. BTW, I don’t want to define an object that includes a and b since these parameters are dynamic.
you can use
dynamicreference System.Web.Extensions
edit
after looking , you are not sending JSON to .net !!!
===>
'{"a":["1,","2&"],"b":4}'you should send the STRING value rather then the OBJECT which you did !
now youll have :
change :
and in c# read :
myValue