简体   繁体   English

Java,Google App Engine和JSONArray / JSONObject

[英]Java, Google App Engine, and JSONArray/JSONObject

I'm working on an assignment and I can't seem to get a response from my instructor or the TA. 我正在做作业,但似乎无法从老师或助教那里得到答复。 The goal of the assignment is to use the Google App Engine to deploy an app that takes the URL of an image, converts it into a byte stream, stores it in the DataStore, then calls it back to be viewed on another page. 分配的目标是使用Google App Engine部署一个应用程序,该应用程序获取图像的URL,将其转换为字节流,将其存储在DataStore中,然后将其调回以在另一页面上查看。

I've been able to store the image, but retrieving it is another matter. 我已经能够存储图像,但是检索它是另一回事。 We're supposed to use JSON arrays and objects to pass a string with the relevant data to a calling function, but Eclipse is telling me that GAE does not support JSON. 我们应该使用JSON数组和对象将带有相关数据的字符串传递给调用函数,但是Eclipse告诉我GAE不支持JSON。 Here's the error message: 这是错误消息:

org.json.simple.JSONArray is not supported by Google App Engine's Java runtime environment Google App Engine的Java运行时环境不支持org.json.simple.JSONArray

Furthermore, the Eclipse console is telling 此外,Eclipse控制台告诉

JSONArray cannot be resolved to a type JSONArray无法解析为类型

and

JSONObject cannot be resolved to a type JSONObject无法解析为类型

What's really odd about this is that the instructor himself uses JSON in his demo app. 真正奇怪的是,讲师本人在其演示应用程序中使用了JSON。 I wish I could get a response from him regarding this issue, but he's being dodgy and has been somewhat absent all term. 我希望我能就此问题得到他的答复,但他一直很狡猾,整个学期都缺席。

Anyway, here's what I've got. 无论如何,这就是我所拥有的。 Please let me know if there's something I'm doing wrong. 请让我知道我做错了什么。 For the record, I'm not asking anyone to fix my code for me or give me working code - I'd just like a little help understanding my problem. 作为记录,我不是在要求任何人为我修复代码或为我提供有效的代码-我只是需要一点帮助来理解我的问题。

<%@ page import="java.util.*" %>
<%@ page import="javax.jdo.*" %>
<%@ page import="org.json.simple.*" %>

<%
    PersistenceManager pm = PMF.getPMF().getPersistenceManager();
    try {
        List<University> items = University.loadAll(pm);
        JSONArray array = new JSONArray();
        for (University item : items) {
            JSONObject object = new JSONObject();
            object.put("uname", item.getNameOfUniversity());
            object.put("photoURL", item.getURLOfImage());
            array.add(object);
        }
        out.write(array.toString());
    } finally {
        pm.close();
    }
%>

You need to add the missing jar file to your project . 您需要将丢失的jar文件添加到您的项目中

Also, for easier JSON creating parsing you should take a look at JSON mapper libraries: GSON or Jackson . 另外,为了更轻松地创建JSON,您应该查看JSON映射器库: GSONJackson

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

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