开发者

XMLHttpRequest - JSON - .NET

I am trying to send JSON from my mozilla addon t开发者_JAVA技巧o my asp.net page.

var myJSONObject = {"userName": una,"password": pass}; request = new XMLHttpRequest(); request.open("GET","http://www.google.com?jo=" + myJSONObject,true, null, null);

on my .net page I have tried several ways of doing it but not able to find the best way to serialize and deserialize the code.

All I need is to send the json data back n forth and parse it on C# n javascript.

I have tried DataContractJsonSerializer, JavaScriptSerilizer among many other things. But not able to make any of it work. With the JavaScriptSerilizer, It does deserilize it if it takes an argument from the browser for e.g. If I open up the browser and paste something like http://www.google.com?jo={"Username":"hna123","Password":"2444"} it does deserilize and return me individual values, but it does work when I do an XMLHTTPRequest (as above) from my mozilla addon. Any clues?


If you want to pass data as querystring then you need to append that to the url using ?.

Try changing the request url from

request.open("GET",http://www.google.com/jo=" + myJSONObject

to

request.open("GET",http://www.google.com?jo=" + myJSONObject

and the use Request.QueryString collection to get the value in C# like

Request.QueryString["jo"]


You need to parse the QueryString yourself to an object in the code behind file to access individual elements of the json.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜