如何使用asp classic从JSON解析瑞典语?

 收藏

我试图解析我从ASP Classic中的XmlHttp请求获得的JSON响应字符串。

我的问题是我的瑞典语字符ä变成\ xE4,å和ö也一样。

我使用aspJSON.asp进行解析,并设置瑞典语的response.LCID = 1053,包括aspJSON.asp并简短地发送并像这样返回响应。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../koppling.asp" -->
<!--#include file="aspJSON1.17.asp" -->
<%Response.LCID = 1053%>
<%
    Response.charset="utf-8"
    Response.CodePage = 65001 
    Set objXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")

        objXmlHttp.Open "GET", url, False
        objXmlHttp.SetRequestHeader "Content-Type", "application/json"
        objXmlHttp.SetRequestHeader "User-Agent", "ASP/3.0"
        objXmlHttp.Send ()


    If objXmlHttp.Status = 200 Then

            jsonstring = CStr(objXmlHttp.ResponseText)
            'response.write jsonstring 
            Set oJSON = New aspJSON

            'Load JSON string
            oJSON.loadJSON(jsonstring)

            'getting the JSON value like this
            fnamn=oJSON.data("payment").item("consumer").item("privatePerson").item("firstName")

并且当fnamn中包含åäö时,我无法将其插入到我的数据库中,因为我收到此错误“错误的字符串值:'\ xE4gen'”,并且其原因是响应中带有ä。

那么为什么不按原样转换角色,我该怎么做呢?

任何输入都非常感谢,谢谢。

编辑

OK, so I added Response.CodePage = 65001 to the page and now the "fnamn" is writing the correct ä when I write response.write fnamn

但是当我尝试将其插入到我的mysql数据库中时仍然出现此错误?

Microsoft OLE DB Provider for ODBC Drivers fel '80004005'

[MySQL][ODBC 3.51 Driver][mysqld-5.7.21-log]Incorrect string value: '\xE4gen' for column 'adress' at row 1

And this part \xE4 is the ä character.

这是我得到回应时的空洞儿子。

{"payment":{"paymentId":"51abf1fa7a014459b1e591dc534e9354","summary":{"reservedAmount":17000,"chargedAmount":17000},"consumer":{"shippingAddress":{"addressLine1":"Centralvägen","receiverLine":"Per Henrik Nordin","postalCode":"83162","city":"ÖSTERSUND","country":"SWE"},"company":{"contactDetails":{"phoneNumber":{}}},"privatePerson":{"firstName":"Per Henrik","lastName":"Nordin","email":"info@manmade.se","phoneNumber":{"prefix":"+46","number":"702315096"}}},"paymentDetails":{"paymentType":"CARD","paymentMethod":"Visa","invoiceDetails":{},"cardDetails":{"maskedPan":"492500******0004","expiryDate":"0320"}},"orderDetails":{"amount":17000,"currency":"SEK","reference":"860153"},"checkout":{"url":"https://www.manmade.se/dumpen/index.asp"},"created":"2019-05-19T04:19:31.5198+00:00","charges":[{"chargeId":"1306fbec6fcd4d68a3681bd16f9de1ec","amount":17000,"created":"2019-05-19T06:19:52.8161+02:00","orderItems":[{"reference":"2-1530","name":"Svart Budda huvud","quantity":1.0,"unit":"st","unitPrice":12800,"taxRate":2500,"taxAmount":4200,"grossTotalAmount":17000,"netTotalAmount":12800}]}]}}

并且两个问题是上面的addressLine1和city,因为它们中有ä和Ö。 我从中得到了价值。

adress=oJSON.data("payment").item("consumer").item("shippingAddress").item("addressLine1")

postadress=oJSON.data("payment").item("consumer").item("shippingAddress").item("city")

然后,我尝试用此sql插入它们。

sql= "INSERT INTO ordrar(userId,appusers_id,paymentId,produkt_id,produkter_id,ordernummer,antal,pris,fraktkostnad,artikel,texten,artikelnummer,farg,fargnummer,storlek,datum,betald,annonser_id,korttyp,kortnr,chargeId,big_image,big_image2,big_image3,big_image4,big_image5,betaltbelopp,email,fnamn,enamn,adress,postnr,postadress,mobil,annonstyp,annonsstatus) VALUES ("&rs("userId")&","& appusersId &",'"& dibspaymentId &"',"& rs("produkt_id") &","& rs("produkter_id") &",'"& dibsordernr &"',"& rs("antal") &","& rs("pris") &","& rs("fraktkostnad") &",'"& rs("artikel") &"','"& rs("texten") &"','"& rs("artikelnummer") &"','"& rs("farg") &"','"& rs("fargnummer") &"','"& rs("storlek") &"','"& rs("datum") &"','"&betald&"',"& rs("annonser_id") &",'"&dibspaymentMetod&"','"&dibskortNr&"','"&dibschargeId&"','"& rs("big_image") &"','"& rs("big_image2") &"','"& rs("big_image3") &"','"& rs("big_image4") &"','"& rs("big_image5") &"','"& dibssumma &"','"& email &"','"& fnamn &"','"& enamn &"','"& adress &"','"& postnr &"','"& postadress &"','"& mobil &"','"& annonstyp &"','ejgranskad');"

But since it displays the ä correctly when I write response.write adress, I don´t understand why it says that it is Incorrect string value: '\xE4gen' for column 'adress' ?

回复