草庐IT

java - JSON 错误 "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"

publicinterfaceUserService{@POST(Constants.Api.URL_REGISTRATION)@FormUrlEncodedBaseWrapperregisterUser(@Field("first_name")Stringfirstname,@Field("last_name")Stringlastname,@Field("regNumber")Stringphone,@Field("regRole")introle);publicBaseWrapperregisterUser(Useruser){returngetUserService().reg

java - 如何在 Retrofit for Android 中处理可选的 JSON 字段?

我正在为Android应用程序开发JSON解析器。当我调用服务器获取数据时,有一些可选字段,我如何使用GSON转换器在Retrofit中处理它?正常react{"status":"SUCCESS","class-1":{"class.enddate":"Jan/10/2016","class.startdate":"Jan/10/2015","class.title":"Physics1","class.short.description":"Physics1","class.description":"ThisisaPhysicsClass"}}备用响应,当某些字段没有任何数据时{"

android - jackson JSON 解析器性能

Internet上的多个帖子都指出Jackson具有比GSON更好的解析性能,速度提高了大约20-30%。http://rick-hightower.blogspot.com/2014/04/new-json-serialization-benchmark.htmlhttp://tuhrig.de/jaxb-vs-gson-and-jackson/http://java.dzone.com/articles/be-lazy-productive-android取出我们的GSON解析器并替换为Jackson导致我的项目减速7倍,每次调用的延迟超过300毫秒。GSON上的相同解析作业耗时不

android - 用于 retrofit 的自定义转换器

我正在尝试使用自定义转换器进行改造RestAdapter.Builderbuilder=newRestAdapter.Builder().setEndpoint(BuildConfig.BASE_SERVER_ENDPOINT).setClient(newOkClient(client)).setConverter(newCitationResponseConverter()).setLogLevel(RestAdapter.LogLevel.FULL);下面是我的自定义转换器publicclassCitationResponseConverterimplementsConverter

android - 如何在 Retrofit GET 请求中发送对象参数?

我有一个这样工作的后端服务器"api/videos?search_object={"cat_id":2,"channel_id":3,etc}基本上,您可以提供一个搜索对象作为输入,它会根据该对象过滤列表。现在我想通过这样的方式将此服务与Retrofit一起使用@GET("videos")CalllistVideos(@Query("search_object")VideoSearchObjectvideoSearchObject);但上面的代码不起作用,我可以先将VideoSearchModel转换为JSON字符串,然后将其传递给这样的改造@GET("videos")Calllist

android - 改造抛出错误预期为 BEGIN_ARRAY 但为 BEGIN_OBJECT

您好,我是Retrofit库的新手,我在解析某些json时遇到问题。我已经查看了Stackoverflow上的其他一些解决方案,但对我的问题不太满意。我试图让一个简单的网络服务工作。任何建议将不胜感激..Json文件{"employees":[{"firstName":"John","lastName":"Doe"},{"firstName":"Anna","lastName":"Smith"},{"firstName":"Peter","lastName":"Jones"}]}请求方式publicvoidrequestEmployeeData(Stringuri){RestAdapt

android - Gson 中的 RuntimeException 解析 JSON : Failed to invoke protected java. lang.ClassLoader() with no args

我继承了一些使用Gson将我们的应用程序状态保存为JSON的代码,然后使用fromJson读取它.Gsongson=createGson();gson.fromJson(objString,myClass);正在保存的字段之一是Location.不幸的是,有时解析保存的数据会失败,因为我保存的位置在其mExtras中包含一个mClassLoader,而Gson库无法创建类加载器并出现此错误:RuntimeException:Failedtoinvokeprotectedjava.lang.ClassLoader()withnoargs有谁知道为什么ClassLoader被包含在我的Lo

android - 用于 Gson 的 POJO 是否可以重用于与 Room 一起使用的类

当使用Gson时,它会创建POJO来解析/序列化来自远程服务的json数据结果。它可能有一些Gson的注解publicclassUser{@SerializedName(“_id”)@ExposepublicStringid;@SerializedName(“_name”)@ExposepublicStringname;@SerializedName(“_lastName”)@ExposepublicStringlastName;@SerializedName(“_age”)@ExposepublicIntegerage;}但对于与Room一起使用的类,它可能有自己的注释:import

java - 在 Android 上使用 GSON 将 JSON 日期格式解析为字符串

我从JSON提要中获取了很多日期。它们看起来像这样:\/Date(1307972400000+0200)\/我需要使用Java将这些日期解析为小时和分钟。编辑:这是我走了多远:Strings=dateString.replaceAll("^/Date\\(","");这给了我以下输出:1307972400000+0200)/我怎样才能去掉这个字符串的其余部分,有什么建议吗?我希望它像这样:1307972400000L 最佳答案 它是来自.Net服务的JSON提要。我正在使用这段代码:publicclassGsonHelper{pub

java - 使用Gson解析Json数组和没有名字的对象

我知道有很多关于GSON的JSON问题,但没有一个与我直接相关。我的JSON格式不同。我有一个JSON数据,我想使用GSON解析它,如下所示:[{"foo":"1","bar":[{"_id":"bar1"}],"too":["mall","park"]}]我有模型类:ItemArray类publicclassItemArray{ListitemArray;//Getsethere}元素等级publicclassItem{Stringfoo;Listbar;Listtoo;//Getsethere}酒吧类publicclassBar{Stringid;//Getsethere}问题来了