gpt4 book ai didi

java - 无法将 google-api-services-admin-directory 组织转换为 JSONArray。因为缺少 customType 值

转载 作者:行者123 更新时间:2023-12-02 02:01:12 25 4
gpt4 key购买 nike

我无法将 google-api-services-admin-directory Organization 转换为 JSONArray,因为会引发以下异常:

Exception message : Missing value at character 38

我有这个代码:

Get user = directoryService.users().get("mangesh@domain.in");

User domainUserObj = user.execute();

logger.warning("Organizations "+domainUserObj.getOrganizations());

JSONArray userOrgJsonArr = new JSONArray(domainUserObj.getOrganizations().toString());

logger.warning("Organizations-JsonArr "+userOrgJsonArr);

我从 API 获取数据是这样的

Organizations [{title=Dev, primary=true, customType=, department=R&D, description=Permanant, costCenter=Cost Test 12}]

我使用的 JAR 版本是 google-api-services-admin-directory-directory_v1-rev72-1.22.0.jar

完整的异常堆栈跟踪

2018 年 7 月 26 日 7:57:52 PM com.company.project.ApiTestServelet doGet警告:组织 [{title=Dev、primary=true、customType=、department=R&D、description=Permanant、costCenter=Cost Test 12}]

Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING: Exception message : Missing value at character 38 Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING: Error in class ApiTestServelet Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.json.JSONTokener.syntaxError(JSONTokener.java:410) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING: org.json.JSONTokener.nextValue(JSONTokener.java:369) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.json.JSONObject.(JSONObject.java:205) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.json.JSONTokener.nextValue(JSONTokener.java:344) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING: org.json.JSONArray.(JSONArray.java:125) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING: org.json.JSONArray.(JSONArray.java:157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.company.project.ApiTestServelet.doGet(ApiTestServelet.java:122) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
javax.servlet.http.HttpServlet.service(HttpServlet.java:617) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.company.project.filter.XSSFilter.doFilter(XSSFilter.java:69) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:72) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:134) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.DevAppServerRequestLogFilter.doFilter(DevAppServerRequestLogFilter.java:44) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:95) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:508) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.Server.handle(Server.java:326) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) Jul 26, 2018 7:57:52 PM com.company.project.utility.ErrorHandler errorHandler WARNING:
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

最佳答案

我找到了一个解决方案,那就是使用com.google.api.client.util.ArrayMap来迭代数据。

但我不明白为什么 API 中的 customType 为空。

ArrayList orgArrList = (java.util.ArrayList)domainUserObj.getOrganizations();

for(int i = 0 ; i < orgArrList.size(); i++) {
System.out.println("For getOrganizations ::"+orgArrList.get(i));
ArrayMap<String,String> orgMapArr = (ArrayMap<String, String>)
orgArrList.get(i);
System.out.println("ArrayMap-UserOrganization ::"+orgMapArr);
for(int index=0; index < orgMapArr.size();index++) {
try {
System.out.println(orgMapArr.getKey(index) + " "
+ orgMapArr.getValue(index));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

输出:

For getOrganizations ::{title=Dev, primary=true, customType=, department=R&D, description=Permanant, costCenter=Cost Test 12}

ArrayMap-UserOrganization ::{title=Dev, primary=true, customType=, department=R&D, description=Permanant, costCenter=Cost Test 12}

title Dev java.lang.Boolean cannot be cast to java.lang.String customType department R&D description Permanant costCenter Cost Test 12

关于java - 无法将 google-api-services-admin-directory 组织转换为 JSONArray。因为缺少 customType 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51542443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com