简体   繁体   English

从多米诺骨牌访问服务中删除方括号

[英]remove square brackets from domino access services

I want to access Domino data via the Domino Access Services (DAS) as REST provider in java eg 我想通过Domino访问服务(DAS)作为Java中的REST提供程序来访问Domino数据,例如

String url = "http://malin1/fakenames.nsf/api/data/collections/name/groups";
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = new JsonFactory();
JsonParser parser = factory.createParser(new URL(url));
JsonNode rootNode = mapper.readTree(parser);

however, I notice DAS binds the JSON in square brackets: 但是,我注意到DAS将JSON绑定在方括号中:

[
  {
      "@entryid":"1-D68BB54DEA77AC8085256B700078923E",
      "@unid":"D68BB54DEA77AC8085256B700078923E",
      "@noteid":"1182",
      "@position":"1",
      "@read":true,
      "@siblings":3,
      "@form":"Group",
      "name":"LocalDomainAdmins",
      "description":"This group should contain all Domino administrators in your domain. Most system databases and templates give people in this group Manager access."
  },
 {
      "@entryid":"3-9E6EABBF405A1A9985256B020060E64E",
      "@unid":"9E6EABBF405A1A9985256B020060E64E",
      "@noteid":"F46",
      "@position":"3",
      "@read":true,
      "@siblings":3,
      "@form":"Group",
      "name":"OtherDomainServers",
      "description":"You should add all Domino servers in other domains with which you commonly replicate to this group."
  }
]

How can I easily get rid of these brackets? 如何轻松摆脱这些括号?

As already mentioned you should leave them intact. 如前所述,您应该保持它们完整无缺。 You can parse theJSON array for example with Jackson. 您可以使用Jackson来解析JSON数组。

find an example snippet below 在下面找到示例片段

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;
...

String response = ... your posted string
ObjectMapper mapper = new ObjectMapper();
try {
    JsonNode taskIdsjsonNode = mapper.readTree(response);
    for (JsonNode next : taskIdsjsonNode) {
        System.out.printf("%s: %s%n", "@entryid", next.get("@entryid"));
        System.out.printf("%s: %s%n", "name", next.get("name"));
    }
} catch (.... ) {
    // your exception handling goes here
}

output 输出

@entryid: "1-D68BB54DEA77AC8085256B700078923E"
name: "LocalDomainAdmins"
@entryid: "3-9E6EABBF405A1A9985256B020060E64E"
name: "OtherDomainServers"

The brackets are not nasty but a correct notation. 括号不是讨厌的,而是正确的符号。 To access the contens just use [0] in your client side script or with your JSON parser in Java you like. 要访问内容,只需在客户端脚本中使用[0]或与Java中的JSON解析器一起使用即可。

Perhaps the explanation here can help: 也许这里的解释可以帮助您:

https://quintessens.wordpress.com/2015/05/08/processing-json-data-from-domino-access-services-with-jackson/ https://quintessens.wordpress.com/2015/05/08/processing-json-data-from-domino-access-services-with-jackson/

Basically you establish a call to DAS via the Jersey client and then you parse the json via Jackson library to a map in java. 基本上,您是通过Jersey客户端建立对DAS的调用,然后通过Jackson库将json解析为Java中的地图。

During the parsing process you can define which values you want to parse and transform them. 在解析过程中,您可以定义要解析和转换的值。

Take a look at the Person class... 看一下Person类...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM