[英]Can't use JSONObject in Google App Engine (Java) anymore?
Half an hour ago I opened Eclipse to edit a Google App Engine app, previously everything was working fine, no errors, I haven't updated anything (at least not knowingly). 半小时前我打开Eclipse编辑一个Google App Engine应用程序,之前一切正常,没有错误,我没有更新任何东西(至少不知情)。
I had imported: com.google.appengine.repackaged.org.json.JSONObject
without error, however now I get this error: 我导入了:
com.google.appengine.repackaged.org.json.JSONObject
没有错误,但现在我收到此错误:
use of com.google.appengine.repackaged may result in your app breaking without warning
It has never broken before, it came with the Google App Engine download for Eclipse, why has it suddenly started now? 它从未打破过,它随着Eclipse的Google App Engine下载,为什么它现在突然开始? And how can I get rid of it?
我怎么能摆脱它呢? (they change I was making was very small and quick, it would be nice not to have to use a different JSON library)
(他们所做的改变非常小而且很快,不必使用不同的JSON库会很好)
com.google.appengine.repackaged.*
contains internal classes that should not be used by application code. com.google.appengine.repackaged.*
包含应用程序代码不应使用的内部类。
org.json
is implemented by many libraries , for example JSON-Java . org.json
由许多库实现,例如JSON-Java 。 Simply include one of them in your GAE project. 只需在GAE项目中包含其中一个。
AppEngine 1.8.4 use AppEngine 1.8.4使用
com.google.appengine.labs.repackaged.org.json.JSONObject com.google.appengine.labs.repackaged.org.json.JSONObject
In case you don't want to have to figure this all out from first principles, here is a step-by-step: 如果你不想从第一原则中弄清楚这一点,这里是一步一步:
Unfortunately this adds a whole lot of Warnings, but they do seem to be harmless. 不幸的是,这增加了很多警告,但它们似乎确实是无害的。
To get rid of Use of com.google.appengine.repackaged may result in your app breaking without warning. 要摆脱com.google.appengine.repackaged的使用,可能会导致您的应用在没有出现警告的情况下中断。 error simple declare your class with full package name .
error simple使用完整的包名声明您的类。 It solves your problem.
它解决了你的问题。
com.google.appengine.repackaged.com.google.gson.JsonObject jsonObject =
new com.google.appengine.repackaged.com.google.gson.JsonObject();
将我的导入更改为com.google.gson.Gson对我有用。
Package com.google.appengine.repackaged.com.google.gson has been deprecated on the latest appengine version. 软件包com.google.appengine.repackaged.com.google.gson已弃用于最新的appengine版本。 Therefore the following statements
因此以下陈述
import com.google.appengine.repackaged.com.google.gson.Gson;
import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
...
Gson gson = new GsonBuilder().create();
will you give you the following error in your appgengine logs: 你会在appgengine日志中给你以下错误:
java.lang.NoClassDefFoundError: com/google/appengine/repackaged/com/google/gson/JsonElement
You need to use the new Json library instead: 您需要使用新的Json库:
1) add new dependency to your gradle file: 1)为gradle文件添加新的依赖项:
compile 'com.google.code.gson:gson:2.8.1'
2) replace 2)更换
import com.google.appengine.repackaged.com.google.gson.Gson;
import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
with 同
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.