Home > Web Front-end > JS Tutorial > body text

前后台交互过程中json格式如何解析以及如何生成_基础知识

WBOY
Release: 2016-05-16 17:45:13
Original
1207 people have browsed it
前台
复制代码 代码如下:

$.ajax({
type: "POST",
url: "GetMenuRole.ashx",
data: "",
dataType: "json",
success: function (data) {
if (data.Status == false) {
alert(data.ErrorReason);
}
else {
//解析这个菜单列表
alert(data.MenuList);
}
},
error: function (data) {
alert(data);
}
});

后台:(需要使用双引号)
复制代码 代码如下:

string sReturnJson = " \"Status\":\"{0}\",\"MenuList\":\"{1}\",\"ErrorReason\":\"{2}\"";
sReturnJson = string.Format(sReturnJson, "True", sReturnMenuList,string.Empty).Replace("","{").Replace("","}");
context.Response.Write(sReturnJson);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template