asp 怎么接收post过来的json数据,解析出来后写入数据库?

2025-03-21 17:22:51
推荐回答(2个)
回答1:


  

Array.prototype.get = function(x) { return this[x]; };  

function parseJSON(strJSON) { return eval("(" + strJSON + ")"); }  

  

<%  

Dim json, obj  

json = "{a:""aaa"", b:{ name:""bb"", value:""text"" }, c:[""item0"", ""item1"", ""item2""]}"  

Set obj = parseJSON(json)    

Response.Write obj.a & ""  '直接获取

Response.Write obj.b.name & ""  '获取指定key

Response.Write obj.c.length & ""  '获取条数

Response.Write obj.c.get(0) & "" 'C的第一条 
Response.Write obj.c & ""  '获取全部

Set obj = Nothing  

%>

然后就是对应的更新到数据库就行了。

建议让JSON,整条的保存在数据库,取出来的时候这样解释就行了。。。

回答2:

调用toObject方法就好了,对应asp的dit对象