Asp.net 前台有这样一段动态的 JSON
1 <div style="display: none" id="cart_json"> 2 { "cartDishItemList":[ { "dishId":11714661, "dishRevisionId":16028643, "restaurantId":18532, 3 "restaurantName":"\u5609\u65FA", "noServiceBuildingList":"|", "denyOrder":false, 4 "restaurantRevisionId": 268723, "restaurantUuid":"e0265e", "referer":"home_restaurant", 5 "deliveryFee":null, "minimumOrder":18, "name":"\u51AC\u83C7\u84B8\u8089\u997C\u5957\u9910(\u9001\u9752\u83DC)", 6 "discountIdList": [ 0 ], "price":23, "priceString":null, "count":1, "stockCount":null 7 } , { "dishId":11714663, "dishRevisionId":16028645, "restaurantId":18532, "restaurantName":"\u5609\u65FA", 8 "noServiceBuildingList":"|", "denyOrder":false, "restaurantRevisionId": 268723, 9 "restaurantUuid":"e0265e", "referer":"home_restaurant", "deliveryFee":null, "minimumOrder":18, 10 "name":"\u5C0F\u7092\u8089\u5957\u9910(\u9001\u9752\u83DC)", "discountIdList": [ 11 0 ], "price":25, "priceString":null, "count":1, "stockCount":null } ], "cartDiscountItemList":[ 12 ] } 13 </div>
我的是 Webform 项目 不是MVC
问: 我怎么在后台获取 JSON
1、直接用<input type='hidden' value='你的json串' name="json" />,然后后台用Request["json"]获取;
2、从ajax获取该数据,直接post到后台;
3、为div加上runat='server',后台直接访问该对象~
<div style="display: none" id="cart_json">修改为 <div style="display: none" id="cart_json" runat="server">
后台 cart_json.InnerText
既然这个 div 是隐藏的,就可以直接把这段 json 放在隐藏域控件的 value 里面提交到后台。
div换成textarea
后台获取前台的json数据干嘛?
直接在你的div 上加一个 runat="server" 后台就可以用这个div的id来取到值了 divId.innerHtml