NotesJsonNavigator和国际字符

时间:2019-05-09 18:47:09

标签: lotus-domino lotusscript

我有一个想在Lotusscript库中使用的json数据。 我使用NotesJsonNavigator来浏览数据。 如果我将preferredUTF8设置为false,则NotesJSONElements中的值是字符串,但是会删除ö,å,...

等国际字符。

如果将参数preferredUTF8设置为true,则NotesJSONElements中的值是字节数组。 如何在考虑国际字符的情况下将这些字节数组转换为字符串?

示例:

Dim session As New NotesSession
'URL Parameters have to be UTF-8 encoded.
Dim url As string
URL = "https://maps.googleapis.com/maps/api/geocode/json?address=Malm%C3%B6%2C%20Sweden&key=<My Google API Key>"

'Creating the request
Dim webRequest As NotesHTTPRequest
Dim response As Variant
Set webRequest = session.createhttprequest()

'Get response as byte array
webrequest.preferstrings = False
response  = webrequest.Get(URL)

'Throw error if response status is not OK
If InStr(webRequest.Responsecode, "200 OK") = 0 Then
    'Return Status is not OK
    Error 1000, "Request returned response code " + webRequest.responseCode
End If

'Create the JSON NAVIGATOR
Dim jsnav As NotesJSONNavigator
If Not IsArray(response) Then Error 1000, "JSON is nothing"
Set jsnav = session.CreateJSONNavigator(response)
'Get data as Strings
jsnav.Preferutf8 = False


'Declaring json specific elements
Dim el_address As NotesJSONElement
Dim el_state As NotesJSONElement

'Retrieving the address...
Set el_address = jsnav.getelementbypointer("/results/0/formatted_address")
Print el_address.value

'Retrieving state
Set el_state = jsnav.getelementbypointer("/results/0/address_components/1/long_name")
Print el_state.value

此打印

瑞典马尔姆

Skne

1 个答案:

答案 0 :(得分:3)

此问题将在下一个10.0.1 FP中修复。请在修复列表中关注DCONB8F6JV。