我有这个Json String:
{"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转换为Object:
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;
答案 0 :(得分:1)
这是因为id是静态的。
答案 1 :(得分:1)
原因是id
是静态的,它属于类,而不是对象。尝试将其用作非静态成员。