62,046
社区成员
发帖
与我相关
我的任务
分享
{
“orderId”:"000001",
"goodsId[0]":"001",
"goodsId[2]":"002",
"goodsId[3]":"003",
}
public string orderId{get;set;}
public string[] goodsId{get;set;}
$.prototype.serializeObject = function () {
var o = {};
var a = $(this).serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
然后 标签name 命名固定, 这个方法会固定给你产生对应的数组。后台就使用 string[] 接收。
//json转换
string strJsonValue = "{\"orderId\":\"000001\",\"goodsId[0]\":\"001\",\"goodsId[3]\":\"003\",\"goodsId[10]\":\"new data\"}";
JObject jsonObj = JsonConvert.DeserializeObject(strJsonValue) as JObject;
//获取指定Key值
string strKey = "goodsId[10]";
string strData = jsonObj[strKey].Value<string>(); //结果: new data