suppose my json stored in string variable. my json look like
"{\"file\":\"dave\",\"type\":\"ward\"}"
the above data stored like in my string variable. now how can i deserialize this json data and read each component like file and type.
i tried with the below code but getting error
var jss = new JavaScriptSerializer();
string json = new StreamReader(context.Request.InputStream).ReadToEnd();
var sData=jss.Deserialize<string>(json);
string _file = sData[0].ToString();
string _type = sData[1].ToString();
please guide my how can i extract each component like file and type after deserialize this from data in json format. thanks
Rectification
This way i solve this....here is whole client side & server side code.
<script type="text/javascript">
$(document).ready(function () {
$('#btnlogin').click(function (e) {
var FeedCrd = {};
FeedCrd["file"] = 'dave';
FeedCrd["type"] = 'ward';
$.ajax({
type: "POST",
url: "CallASHX.ashx",
data: JSON.stringify(FeedCrd),
//data: { 'file': 'dave', 'type': 'ward' },
//dataType: "json",
success: function (data) {
if (data == "SUCCESS");
{
alert('SUCCESS');
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
return false;
});
});
</script>
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
var jss = new JavaScriptSerializer();
string json = new StreamReader(context.Request.InputStream).ReadToEnd();
Dictionary<string,string> sData=jss.Deserialize<Dictionary<string,string>>(json);
string _file = sData["file"].ToString();
string _type = sData["type"].ToString();
context.Response.Write("SUCCESS");
}