首页 > 解决方案 > NotesJSONNavigator 在解析具有空字符串值的包时遇到严重问题

问题描述

我正在使用新的 NotesJSONNavigator 对象来解析来自第三方 API 的响应。我观察到的响应看起来格式正确(JSON),但我的代码吐出了一些奇怪的结果。

我将其缩小到由空字符串表示的 JSON 值。在这些情况下,从 JSON 中检索到的“值”是不可预测的和随机的(系统字符)。

我准备了一个示例测试 JSON 包字符串,并且可以使用以下逻辑可靠地重现结果......我在这里遗漏了什么吗?

response$ = |{"resultcode":200,"result":[{"id":41,"eMail Address":"test@abc.com"},{"id":57,"eMail Address":""}]}|

Set jsonNav = session.CreateJSONNavigator( response$ )
Set jsonEl = jsonNav.GetElementByName( "result" )
Set jsonArr = jsonEl.Value

Set listEl = jsonArr.GetFirstElement()
Do While Not( listEl Is Nothing )
    Set jsonObj = listEl.Value
    checkEmail = jsonObj.GetElementByName( "eMail Address" ).Value
    Set listEl = jsonArr.GetNextElement()       
Loop

只要“电子邮件地址”部分中有数据,一切都解析得很好。如果该数据是一个空字符串(如上面的 ID 57),则 checkEmail 变量被设置为一些非常奇怪的字符并且不是空白的!

标签: lotusscript

解决方案


推荐阅读