草庐IT

android - Retrofit + RealmList + Gson 陷入循环直到内存不足

我正在尝试使用Retrofit+Realm+Gson,但是当使用RealmList时,应用程序卡住了。如果我删除RealmList对象一切正常,但我需要对象列表。日志:(32099):BackgroundstickyconcurrentmarksweepGCfreed278516(15MB)AllocSpaceobjects,0(0B)LOSobjects,25%free,23MB/31MB,paused2.533mstotal1.049s(32099):BackgroundpartialconcurrentmarksweepGCfreed137132(8MB)AllocSpaceob

android - Gson序列化HashMap<Teacher, List<Student>>

我有一个map,其中一个键的值是一个对象列表。能够通过builder.enableComplexMapKeySerialization();序列化key但是这些值没有按预期序列化,因为它们在反序列化时返回字符串而不是对象。下面是序列化的输出[{"id":31001,"name":Teacher"]},//Thisisthekey[{"id":33033,"name":"student1"},{"id":34001,"name":"student2"}]],//Thisisthelistofvalues我使用了相关的TypeToken,它是TypeToken>>但列表值仍然在反序列化时返

android - 改造 - 在将其解析为 json 之前从响应主体中删除一些无效字符

我有一个外部Web服务,它在响应正文中返回json但嵌套在括号中,如下所示:({"door_x":"103994.001461","door_y":"98780.7862376","distance":"53.3"})使用这段代码:classAddressInfo{Stringdoor_x;Stringdoor_y;}interfaceAddressWebService{@GET("/reversegeocoding")AddressInforeverseGeocoding(@Query("x")doublex,@Query("y")doubley);}显然失败了。这是堆栈跟踪:ret

Android Retrofit 应为 BEGIN_OBJECT 但在第 1 行第 1 列路径 $ 处为 STRING

我在我的Android应用程序中使用okhttpRetrofit来发出网络请求。在其中一个请求中,我收到此错误:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:应为BEGIN_OBJECT但在第1行第1列路径$我在日志中看到201响应,但Retrofit抛出此错误。下面是我的代码。signup(signupParams,newCallback(){@Overridepublicvoidsuccess(Membermember,Responseresponse){if(member!=null){Us

android - 使用 Retrofit 获取错误 onFailure : com. google.gson.JsonSyntaxException : java. lang.IllegalStateException: closed

我在将OkHttpClient对象添加到改造中时遇到错误。错误是:com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:closed这是我的代码:publicstaticOkHttpClientgetUnsafeOkHttpClient(){try{FilemFolder=newFile(Environment.getExternalStorageDirectory()+"/certificate");if(!mFolder.exists()){mFolder.mkdir();}StringfileNam

android - 使用 GSON 库从 URL(RESTful web 服务)解析 JSON 字符串。安卓

阅读之前:我在这个程序中使用了可下载的GSON库。http://webscripts.softpedia.com/script/Development-Scripts-js/Other-Libraries/Gson-71373.html我尝试解析JSON已经有一段时间了,但每次我尝试从URL中获取字符串时,程序都“不起作用”。它不会失败或关闭或出现错误。它只是不做解析。我的程序旨在从http://api.geonames.org/weatherIcaoJSON?ICAO=LSZH&username=demo解析并有一个按钮来更新再次运行解析过程,以便它会刷新信息。如果我使用硬编码的JS

java - 将 DateTimeOffset 从 Android 发送到 .NET Web API

我正在使用适用于Android的Azure移动应用SDK。publicclassMyClass{publicStringId;publicStringCode;publicDateTimeOffsetClientCreatedAt;}MyClassmyClass=newMyClass();myClass.Id="1234567890";myClass.Code="dfgdrvyet";myClass.ClientCreatedAt=newDateTimeOffset(newDate());它的使用如下:MobileServiceSyncTablemyClassSyncTable=_cl

java - RealmList 序列化问题(Realm/Gson/Intent)

我在项目中使用Retrofit、Gson和Realm。我有这个类Example需要Serializable。如果没有Realm,我会这样写:publicclassExampleimplementsSerializable{@SerializationName("users")privateListusers//...gettersandsetters}Realm开始发挥作用,Example变成(请注意,出于兼容性原因,getter和setter是这种方式):publicclassExampleextendsRealmObjectimplementSerializable{@Serial

java - 在处理器生成的类中使用库

我正在开发一个库来使用注释和处理器生成类。生成的类应该使用来自google的Gson库。我的问题是:我应该在哪里添加Gson依赖项?我目前正在将它添加到处理器build.gradle中,但是当生成类时,找不到Gson并且AndroidStudio提示将其添加到应用程序模块。处理器的build.gradle:implementationproject(':lib-annotation')implementation'com.squareup:javapoet:1.9.0'implementation'com.google.code.gson:gson:2.8.1'implementati

android - 改造编码特殊字符

我正在使用gson而非android进行改造,因为它更快、更安全。问题是改造正在编码特殊字符,如=和?,而我使用的url无法解码这些字符。这是我的代码:接口(interface)类:publicinterfaceplaceApi{@GET("/{id}")publicvoidgetFeed(@Path("id")TypedStringid,Callbackresponse);}主类:Stringurl="http://api.beirut.com/BeirutProfile.php?";Stringnext="profileid=111";//Creatingadapterforret