试图获取LotusScript JSON阅读器 [英] Trying to get lotusscript json reader

查看:101
本文介绍了试图获取LotusScript JSON阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过LotusScript,我正在使用一个返回json值的网页,除了openntf的ls.snapps.JSONReader之外,我无法在其中找到任何适用于Lotusscript的库.它可以工作,但是文档有限.我在读取值列表中的嵌套数组时遇到麻烦.我可以使用ibm.common.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 ibm.common.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库

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 http://bastide.org/2014/03/15/using-the-ibm-social-business-toolkit-to-process-json-objects/

这是Java代码:

import com.ibm.commons.util.io.json.JsonException;
import com.ibm.commons.util.io.json.JsonJavaFactory;
import com.ibm.commons.util.io.json.JsonJavaObject;
import com.ibm.commons.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阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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