gpt4 book ai didi

java - Json 到对象不起作用

转载 作者:行者123 更新时间:2023-12-02 05:32:32 25 4
gpt4 key购买 nike

我有这个 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/

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