gpt4 book ai didi

android - 无法使用 robospice 和 ormlite 存储 JSON 请求的嵌套部分

转载 作者:太空狗 更新时间:2023-10-29 15:07:38 24 4
gpt4 key购买 nike

您好,我们将 RoboSpice 与 ORMLite 和 SpringAndroidSpiceRequest 结合使用来阅读来自网页的JSON信息并写入SQLite数据库。

我们正在使用最新的 JSON 映射器 MappingJackson2HttpMessageConverter。

        // Web services support JSON responses
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
FormHttpMessageConverter formHttpMessageConverter = new FormHttpMessageConverter();
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
final List<HttpMessageConverter<?>> listHttpMessageConverters = restTemplate.getMessageConverters();

我们尝试像下面的例子一样读取嵌套的 JSON 查询,我们可以读取并存储到数据库,第一层JSON(page,total),但是我们不能存储JSON 数组的下一个级别,所有“schedule_date”条目。

我们将此示例(以及更多示例)视为存储 JSON 的最佳示例数据。但这对我们不起作用。 RoboSpice persist JSON array with OrmLite

问题:我们如何读取和写入嵌套的 JSON 键和值,我们难倒了! :O

JSON:

{
"page": 2,
"total": 5,
"result":
[
{
"schedule_date": "2013-08-03"
},
{
"schedule_date": "2013-09-03"
},
{
"schedule_date": "2013-10-03"
},
{
"schedule_date": "2013-11-03"
},
{
"schedule_date": "2013-12-03"
}
]
}

BroadcastResult.java:

            import java.util.Collection;
import java.util.List;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.j256.ormlite.field.ForeignCollectionField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
@DatabaseTable(tableName="BroadcastResult")
public class BroadcastResult {

@DatabaseField(id = true)
private int page;

@DatabaseField
private int total;

@ForeignCollectionField(eager = false)
private Collection<Broadcast> result;

public int getPage() {
return page;
}

public void setPage(int page) {
this.page = page;
}

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public Collection<Broadcast> getResult() {
return result;
}

public void setResult(Collection<Broadcast> result) {
this.result = result;
}
}

广播.java:

            import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
@DatabaseTable(tableName="Broadcast")
public class Broadcast {

@DatabaseField(id = true)
private String schedule_date;

@DatabaseField(foreign = true)
private BroadcastResult result;

public String getScheduleDate() {
return schedule_date;
}

public void setScheduleDate(String schedule_date) {
this.schedule_date = schedule_date;
}

public void setBroadcastResult(BroadcastResult result) {
this.result = result;
}

public BroadcastResult getBroadcastResult() {
return result;
}
}

我们遇到了这个错误,我们不明白。
Logcat: SQLiteLog(10637): (1) 没有这样的列:result_id

@DatabaseField(foreign = true) // also tried (foreign = true, ColumnName="result")
private BroadcastResult result;

运行测试的完整日志可以在这里看到: https://gist.github.com/anonymous/7760344

最佳答案

你试过添加

@DatabaseField(generatedId = true)
private int _id;

到您的 Broadcast.java 类?

关于android - 无法使用 robospice 和 ormlite 存储 JSON 请求的嵌套部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20339683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com