试图获取LotusScript JSON阅读器

编程入门 行业动态 更新时间:2024-10-27 02:20:53
本文介绍了试图获取LotusScript JSON阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

通过LotusScript,我正在使用一个返回json值的网页,除了openntf的ls.snapps.JSONReader之外,我无法在其中找到任何适用于Lotusscript的库.它可以工作,但是文档有限.我在读取值列表中的嵌套数组时遇到麻烦.我可以使用ibmmon.utils ....库使它在Java中工作,但是在使用Mac客户端和另一个库(javax.swing.*)时遇到问题,因此我切换到LotusScript.

Through LotusScript I am consuming a webpage that returns json values and I have been unable to find any library out there for lotusscript, other than ls.snapps.JSONReader from openntf. It works, but documentation is limited. I am having trouble reading a nested array in the value list. I was able to get it to work in java using the ibmmon.utils.... library, but was having trouble with mac client and another library (javax.swing.*) so I switched to LotusScript.

我希望其他人对ls.snapps.JSONReader库有经验,或者对如何执行此方法有不同的想法.这是示例:

I am hoping someone else has experience with the ls.snapps.JSONReader library, or maybe a different idea on how to do this. Here is the sample:

我使用它来阅读

Dim jsonReader As jsonReader Dim vResults As Variant Dim vPieces As Variant Dim sJSON As string sJson= |{ "colorsArray":[{ "red":"#f00", "green":"#0f0", "blue":"#00f", "cyan":"#0ff", "magenta":"#f0f", "yellow":"#ff0", "black":"#000" } ] }| Set jsonReader = New JsonReader Set vResults = jsonReader.parse(sJson) vPieces = vResults.items

设置单个级别的对象时,我没有任何麻烦,

I have no trouble when I set a single level object such as:

sJSON = |{"a":"a4255524","a24":true,"ax":"WER!!","b":"Some text"}|

我使用getItemValue方法

I use the getItemValue method

msgbox vResults.getitemValue("a24")

将返回"true"值

有人使用过这个JSON解析器吗?您能给我一些有关如何获取数据的建议吗?

Has anyone used this JSON parser and can you give me some advice on how to get the data out?

更新和临时解决方案: 要获取json值,我必须执行以下两项操作之一:

UPDATE and interim solution: To get json values I had to do one of two things:

  • 使用ls替换函数提取一维数据(即,删除{"colorsArray":[左侧和]},然后使用snapps json阅读器.

  • use ls Replace functions to extract the single dimension data (ie, remove {"colorsArray":[ on the left side and ]} on the right side., then use snapps json reader.

我使用SBT JSON库创建了一个Java库,并从LotusScript对其进行了调用. Paul Bastide在使用Java库 bastide/2014/03/15/using-the-ibm-social-business-toolkit-to-process-json-objects/

I created a java library using the SBT JSON libs and called it from LotusScript. Paul Bastide put a good writeup on using the java lib bastide/2014/03/15/using-the-ibm-social-business-toolkit-to-process-json-objects/

这是Java代码:

import com.ibmmons.util.io.json.JsonException; import com.ibmmons.util.io.json.JsonJavaFactory; import com.ibmmons.util.io.json.JsonJavaObject; import com.ibmmons.util.io.json.JsonParser; import com.ibm.sbt.services.client.base.datahandlers.JsonDataHandler; import lotus.domino.*; public class GetJSON extends AgentBase { public static String pJSON( String jData, String jEntry, String jValue ) { String result2=""; try { System.out.println("data: " + jData + "\n" + "\n" + "jEntry & jValue: " + jEntry + ", " + jValue); // print to debug console // System.out.println("jData: " + jData); JsonJavaObject jsonObject = (JsonJavaObject) JsonParser.fromJson(JsonJavaFactory.instanceEx, jData ); JsonDataHandler handler = new JsonDataHandler(); handler.setData(jsonObject); JsonJavaObject entryJson=handler.getEntry(jEntry); result2=entryJson.getAsString(jValue); } catch (Exception e) { System.out.println("Error: " + e); e.printStackTrace(); result2=""; } return result2; } }

我从LotusScript中按如下方式调用它:

and I call it from LotusScript as follows:

Option Public Option Declare Use "($getJson)" UseLSX "*javacon" Dim mySession As JavaSession Dim myClass As JavaClass Dim getJson As JavaObject result = "" '.... 'add vars here '.... Set mySession = New JavaSession() Set myClass = mySession.GetClass("GetJSON") Set GetJson = myClass.CreateObject() MsgBox GetJson.pJSON( result2, "colorsArray", "red" )

上面的重要说明,在数组字符串中,我必须删除方括号[和],因为我在Java中遇到了SBT数组不兼容错误.我认为这样做可能会使它变成一个单一级别的对象,但是如果您从上面的URL看Paul的示例,您会发现他也没有将它们添加到他的示例中.

IMPORTANT NOTE on the above, in the array string I had to remove the brackets [ and ] because I was getting an SBT array incompatibility error in java. I think by doing that it may have turned it into a single level object, but if you look at Paul's example from above URL, you'll see he doesn't add them to his example either.

我宁愿在所有Java或所有LotusScript中执行此操作,并且可能会在快照中使用经过修改的json字符串,只是在寻找更好的解决方案.

I would rather do this in all Java or all LotusScript, and will probably use the modified json string with snapps, just looking for a better solution.

推荐答案

这是您的JSON字符串的工作代码.试试吧.

Here is the working code for your JSON string. Try it.

Dim jsonReader As JSONReader Dim vResults As Variant Dim vPieces As Variant Dim sJSON As String sJson= |{ "colorsArray":[{ "red":"#f00", "green":"#0f0", "blue":"#00f", "cyan":"#0ff", "magenta":"#f0f", "yellow":"#ff0", "black":"#000" } ]}| Set jsonReader = New JSONReader Set vResults = jsonReader.parse(sJson) Set vResultData = vResults.GetItemValue("colorsArray") Forall vResult In vResultData.Items Msgbox Cstr(vResult.GetItemValue("red")) Msgbox Cstr(vResult.GetItemValue("green")) Msgbox Cstr(vResult.GetItemValue("blue")) Msgbox Cstr(vResult.GetItemValue("cyan")) Msgbox Cstr(vResult.GetItemValue("magenta")) Msgbox Cstr(vResult.GetItemValue("yellow")) Msgbox Cstr(vResult.GetItemValue("black")) End Forall

更多推荐

试图获取LotusScript JSON阅读器

本文发布于:2023-07-15 23:05:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1115295.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阅读器   LotusScript   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!