- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在解析 JSON 数据时遇到以下错误:
应为 begin_array 但在第 1 行第 34 列为 STRING
我找不到解决方案。我的 JSON 如下:
{"result":0,"count":2,"records":"[{\"name\":\"name1\",
\"id\":\"28\",
\"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/28\\\/tb_uykzubjqmxbv6zkogdsd_c64962310e572f5e8a4c73a44a4fa3dd.jpg\"},{\"name\":\"name2\",
\"id\":\"134\",
\"photo\":\"\\\/gallery\\\/c9\\\/f0f8\\\/95fb\\\/c9f0f895fb98ab9159f51fd0297e236d\\\/134\\\/tb_23ffxuw9-5ys4iqtwztz_610982fa52cca03412dbc84ab0ea5e18.jpg\"}]"}
这是我的 PersonContent 类:
public class PersonContent {
@SerializedName("result")
public int result;
@SerializedName("count")
public int count;
@SerializedName("records")
List<Person> records;
public List<Person> getRecords() {
return records;
}
public void setRecords(List<Person> records) {
this.records = records;
}
public void setResults(int result) {
this.result = result;
}
public int getResults(){
return result;
}
public void setCount(int count) {
this.count = count;
}
public int getCount(){
return count;
}
下面是Person类:
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@SerializedName("name")
public String name;
@SerializedName("id")
public String id;
@SerializedName("photo")
public String photo;
public Person(){
}
public Person( String name,String id,String photo) {
this.id = id;
this.name = name;
this.photo = photo;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
@Override
public String toString() {
return name;
}
}
这是我反序列化前面提到的 JSON 数据的代码
private void Parse(){
InputStream source = retrieveStream(url);
Gson gson = new Gson();
Reader reader = new InputStreamReader(source);
personlist = gson.fromJson(reader, PersonContent.class);
}
我已经尝试了此处找到的所有解决方案,但找不到相同的 JSON。还有以下内容:com.google.gson.JsonSyntaxException: Expected BEGIN_ARRAY but was STRING
最佳答案
错误在您收到的 json 中:你类(class)需要一个数组,因为
List<Person> records;
但是在你的 json 中你有
“记录”:“[
它必须是:
"records": [
最后 ]"},必须是
]}
关于java - Gson:应为 begin_array 但为 STRING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22795614/
我试图让 gson 在 java 项目上工作,但每次运行时都会出现上述错误。我没有使用任何闪存 IDE,只是 vim,我看到的与我的问题相关的每个问题都与 eclipse 及其部署设置有关。我希望有人
我一直在关注将对象数组转换为 JSON 的教程,但我遇到了一些找不到解决方案的错误。 代码 第 60 - 64 行 Gson gson = new Gson().toJson(data); respo
我正在创建一个新的 Netty 管道,我正在尝试: 避免过早优化。 编写易于向我的一位实习生解释的代码。 这种工厂方法当然很容易解释: public String toJSON() { Gso
我尝试在程序中使用 Unirest,但不断收到此错误 java.lang.NoSuchMethodError: com.google.gson.Gson.newBuilder()Lcom/google
// Retrofit compile 'com.squareup.retrofit2:retrofit:2.1.0' // JSON Parsing compile 'com.google.code
我正在尝试将 Gson 与接口(interface)一起使用: public interface Photo { public int getWidth(); } public class D
我正在执行一个 Web 服务,这是我的响应,但是当我尝试使用 Gson 库将此 JSONObject(org.json.JSONObject) 转换为特定对象时,我的应用程序崩溃了。所以,我不知道为什
我有以下 .json 文件 - { "IDs":[ "1716136233", "2030187302", "204897807
我试图在我的项目中使用 GSON,但我的应用程序崩溃了,logcat 说找不到 com.google.gson.Gson。我已将 import com.google.gson.Gson 放在我的类文件
在下面的示例中,我尝试序列化我的自定义类Couple,其中包含Point2D 类型的字段。 我发现,SErialzing 的过程取决于 DEserializer 的存在。 此外,如果存在反序列化器,则
我有课 class ThreadComment( banned: Int, closed: Int, comment: String?, date: String?,
使用 gson 解析 json 时,我有一个奇怪的行为。我使用这个代码: private static Container parseContainer(String containerJson) {
我注意到 GSON HTML 转义 字符,可以通过使用disableHtmlEscaping()来禁用它构建器配置方法。但我的问题是 - 为什么 GSON 默认情况下会进行 HTML 转义?不进行 H
我注意到一个奇怪的问题。我可以使用 Junit 运行我的测试用例,但是当我使用 maven 运行时,其中一个测试用例失败。它提示找不到 Gson 类 def。 我能够在 Maven 依赖项中看到 Gs
我有一个看起来像这样的 json {response:{"status":{"....."},data:[{"name":"Alice","id":"123"},{"name":"Jack","id"
所以,我的应用已经发布了将近一年,但没有看到这个问题,现在它出现了。 即使是现在,我的手机上的调试版本也没有这个问题。我对从 Android Studio 打开的任何模拟器没有任何问题。然而,Goog
我是 Android 开发环境的新手,因此需要专家的帮助。 java.lang.NoClassDefFoundError: com.google.gson.Gson 项目中包含 Gson 库,但是当从
总结 我在我的 android 应用程序中使用 Retrofit 和 Gson 有一段时间了,但是我从服务器获得的 ID 是 13 位数字。 Gson 自动将这些数字转换为科学计数法,然后将其转换为
我正在使用一个大的 JSON 对象,它具有来自多个请求的响应。 我正在处理的部分只需要很少的对象,而且它们并不总是在前面。例如 json 结构是: ** json = { mainDocume
我有一个休息网络服务: @Path("/tranreq") public class TranscriptRequesterResource { private static final Gs
我是一名优秀的程序员,十分优秀!