java - Json 到对象不起作用

标签 java json gson

我有这个 Json 字符串:

{"type":"ContactSegment","x_e10_isTemplate":"false","x_e10_createdAt":"1408441893","x_e10_createdBy":"47","currentStatus":"Draft","id":"384","initialId":"-500023","createdAt":"1408441893","createdBy":"47","depth":"complete","folderId":"1567","name":"Untitled Segment delete me","permissions":[2,5,4,3],"updatedAt":"1408441893","updatedBy":"47","elements":[{"type":"ContactFilterSegmentElement","id":"629","initialId":"-500025","depth":"complete","count":"0","isIncluded":"true","lastCalculatedAt":"1408441893","filter":{"type":"ContactFilter","x_e10_isTemplate":"false","x_e10_createdAt":"1408441893","x_e10_createdBy":"47","currentStatus":"Draft","id":"100584","initialId":"-500024","createdAt":"1408441893","createdBy":"47","depth":"complete","folderId":"51","name":"Filter Criteria 1","permissions":[2,5,4,3],"updatedAt":"1408441893","updatedBy":"47","criteria":[{"type":"CampaignResponderCriterion","id":"1216","initialId":"-500026","activityRestriction":{"type":"NumericValueCondition","operator":"notLess","value":"1"},"timeRestriction":{"type":"DateValueCondition","operator":"withinLast","value":{"type":"RelativeDate","offset":"1","timePeriod":"day"}},"campaignIds":["313"]}],"scope":"local","statement":"1216"}}]}

我使用 GSON 将 JSON 转换为对象:

ContactSegment segment = new ContactSegment();
    Gson gson = new Gson();
    segment = gson.fromJson(response.body, ContactSegment.class);

这是 ContactSegment 类:

public class ContactSegment {

public static String id;
}

当我尝试执行segment.id时,它返回null;

最佳答案

原因是id是静态的,它属于类,而不是对象。尝试将其用作非静态成员。

关于java - Json 到对象不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25380514/

相关文章:

java - JPA 具有动态 WHERE 语句并处理 MVC 中的 JPA 连接

javascript - 不能在 JSON 上使用点符号

Android Proguard ExceptionInInitializerError 和 RuntimeException

java - 使用泛型类型传递特定类

json - 根据jq json中的where子句提取元素

android - 使用 GSON 库导出/签名 Android 项目

android - Retrofit 2.0 具有不同子类型的嵌套 json

java - javacompareTo中的多个方法进行比较?

java - 如何用UML类图表达Factory或Helper类和它能生成的对象的关系

java - 来自服务器的响应代码