如何在ESQL中访问JSON子节点数据? [英] How do I access JSON child node data in ESQL?

查看:122
本文介绍了如何在ESQL中访问JSON子节点数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常感谢您帮我看看.

我正在使用IBM ACE V11软件,在服务中,我收到JSON消息.

I am working in IBM ACE V11 software and in my service, I receive a JSON message.

我需要通过ESQL将此JSON消息映射到SOAP请求.

I need to map this JSON message to a SOAP request via ESQL.

请参见下面的示例消息:

Please see the sample message below:

传入的JSON消息:

   "journals": [
                    {
                            "journalName": "Plant Species in London",
                            "journalYear": "2016",
                            "journalAuthor": [
                                    {
                                            "name": "Julian Bose",
                                            "subject": "botany"
                                    }
                                    {
                                            "name": "Samantha Adams",
                                            "subject": "biology"
                                    }, 
                            ],
                            "samplePolling": {
                                    "pollingInterval": 120,
                                    "totalAttempts": 10
                            }
                    },
              
            ],
            "supervisorName": "James Smith"
    }

到目前为止,在ESQL中:

In ESQL I have so far:

对于期刊名称:

SET OutputRoot.SOAP.Body.ns:submitJournal.ns:journalName = InputRoot.JSON.Data.journals.journalName;  

期刊年份:

SET OutputRoot.SOAP.Body.ns:submitJournal.ns:journalYear = InputRoot.JSON.Data.journals.journalYear;  

对于Journal的作者,我有问题.问题是可能有0到3个或更多作者. 在这种情况下,有2位作者.

For Journal's Author, I have a problem. The problem is that there can be 0 to 3 or more authors. In this case, there are 2 authors.

我如何首先检查是否存在任何作者,如果存在,则有多少作者,然后如何将每个作者的详细信息分配给SOAP. (所有这些都在ESQL中进行.)

How do I first check if any authors are present and if so, how many are there and then how to assign each authors' details to SOAP. (All of this in ESQL).

到目前为止,在ESQL中我已经做到了.但是我不知道如何获得n.价值. (n代表作者人数).

In ESQL I have this so far. But I don't know how to get the "n" value. (n represents no. of authors).

SET OutputRoot.SOAP.Body.ns:submitJournal.ns:journalAuthorValues[n].ns16:AuthorName = InputRoot.JSON.journals.journalAuthor[n].name; 

任何帮助都将不胜感激.

Any and all help is greatly appreciated.

推荐答案

对于Journal的作者,我有问题.问题是可能有0到3个或更多作者.在这种情况下,有2位作者.

For Journal's Author, I have a problem. The problem is that there can be 0 to 3 or more authors. In this case, there are 2 authors.

您需要遍历作者数组,并且假设您需要 count 个作者数量.但是您不需要.这应该可以正常工作(未经测试,可能包含语法错误)

You need to iterate over the array of authors, and you are assuming that you need to count the number of authors. But you do not need to. This should work just fine (not tested, may contain syntax errors)

FOR refAuthor AS InputRoot.JSON.Data.journals.(JSON.Array)journalAuthor[] DO
    CREATE LASTCHILD OF OutputRoot.SOAP.Body.ns:submitJournal.ns:journalAuthorValues 
       TYPE NAMEVALUE
       IDENTITY ns16:AuthorName
       VALUE FIELDVALUE(refAuthor);
END FOR

您应该尝试避免在ESQL中使用计数循环.一条FOR语句或一条SELECT语句几乎总是更简单,更好.

You should try to avoid using counted loops in ESQL. A FOR statement or a SELECT statement is almost always simpler and better.

这篇关于如何在ESQL中访问JSON子节点数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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