Json to SQL ASP经典 [英] Json to SQL ASP classic

查看:163
本文介绍了Json to SQL ASP经典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法弄清楚如何使用ASP Classic解决此问题,外部服务器会向我发送一些Json到我的网站 前任. www.mypage.com/getjson.asp

Can´t figure out how to solve this with ASP Classic, an external server will send me some Json to my site ex. www.mypage.com/getjson.asp

{"Userid":"112233","Member":Tom}

我该如何获取并检查Userid是否已存在,否则将其放入SQL

How can I fetch this and check if the Userid already exist, otherwise put it in the SQL

如果该用户名存在,我只需要回答

If the userid exist I just have to answer

response.Write "{""Userid"": true}"

我可以将其转换"为查询字符串或其他内容吗?

Can I "convert" it to a querystring or somthing ?

感谢您提供的所有帮助,但我无法与该主题中的技巧一起使用 但是我设法用这段代码得到了整个字符串

Thanks for all help, but I coundn´t get it to work with the tips in this thread But I managed to get the whole string whit this code

bytecount = Request.TotalBytes
bytes = Request.BinaryRead(bytecount)

Set stream = Server.CreateObject("ADODB.Stream")
    stream.Type = 1              
    stream.Open()                                   
        stream.Write(bytes)
        stream.Position = 0                             
        stream.Type = 2                 
        stream.Charset = "utf-8"                      
        s = stream.ReadText()               
    stream.Close()
Set stream = nothing
Response.Write =(s)

但是现在我需要弄清楚如何清理和拆分它, 请注意,会员没有qoutes

But now I need to figure put how to cleanup and split this, note that Member don´t have qoutes

{"Userid":"00004547552009","Member":1,"id":"0060a80040d9"}

推荐答案

如何使用我的实用程序类: https://github.com/rcdmk/aspJSON

And what about use my utility class: https://github.com/rcdmk/aspJSON

自述文件中的一些示例:

Some examples from the README:

' instantiate the class
Dim oJSON = New JSON

' add properties
oJSON.Add "prop1", "someString"
oJSON.Add "prop2", 12.3
oJSON.Add "prop3", Array(1, 2, "three")

' change some values
oJSON.Change "prop1", "someOtherString"
oJSON.Change "prop4", "thisWillBeCreated" ' this property doen't exists and will be created automagically

' get the values
Response.Write oJSON("prop1") & "<br>"
Response.Write oJSON("prop2") & "<br>"
Response.Write oJSON("prop3") & "<br>"
Response.Write oJSON("prop4") & "<br>"

' get the JSON formatted output
Dim jsonSting
jsonString = oJSON.Serialize() ' this will contain the string representation of the JSON object

oJSON.Write() ' this will write the output to the Response - equivalent to: Response.Write oJSON.Serialize()

' load and parse some JSON formatted string
jsonString = "{ ""strings"" : ""valorTexto"", ""numbers"": 123.456, ""arrays"": [1, ""2"", 3.4, [5, 6, [7, 8]]], ""objects"": { ""prop1"": ""outroTexto"", ""prop2"": [ { ""id"": 1, ""name"": ""item1"" }, { ""id"": 2, ""name"": ""item2"", ""teste"": { ""maisum"": [1, 2, 3] } } ] } }" ' double quotes here because of the VBScript quote scaping

oJSON.Parse(jsonString) ' set this to a variable if your string to load can be an Array, since the function returns the parsed object and arrays are parsed to JSONarray objects
' if the string represents an object, the current object is returned so there is not need to set the return to a new variable

oJSON.Write()

一段时间前,我已经添加了一些方法来加载记录集和二维数组.这可以帮助从数据库编写JSON:

I've added methods to load recordsets and bidimensional arrays some time ago. This can help a lot in writing JSON from the database:

' load records from an ADODB.Recordset
dim cn, rs
set cn = CreateObject("ADODB.Connection")
cn.Open "yourConnectionStringGoesHere"

set rs = cn.execute("SELECT id, nome, valor FROM pedidos ORDER BY id ASC")
' this could also be:
' set rs = CreateObject("ADODB.Recordset")
' rs.Open "SELECT id, nome, valor FROM pedidos ORDER BY id ASC", cn 

JSON.LoadRecordset rs
JSONarr.LoadRecordset rs

rs.Close
cn.Close
set rs = Nothing
set cn = Nothing

JSON.Write()        ' outputs: {"data":[{"id":1,"nome":"nome 1","valor":10.99},{"id":2,"nome":"nome 2","valor":19.1}]}
JSONarr.Write()     ' outputs: [{"id":1,"nome":"nome 1","valor":10.99},{"id":2,"nome":"nome 2","valor":19.1}]

这篇关于Json to SQL ASP经典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆