我需要将此 json 字符串解析为值。
“开始”:{“日期时间”:“2013-02-02T15:00:00+05:30”},“结束”:{“日期时间”:“2013-02-02T16:00:00+05:30” },
问题是我在 apex (salesforce) 中使用 JSONParser。我的课是:
public class wrapGoogleData{
public string summary{get;set;}
public string id{get;set;}
public string status;
public creator creator;
public start start;
public wrapGoogleData(string entnm,string ezid,string sta, creator c,start s){
summary= entnm;
id= ezid;
status = sta;
creator = c;
start = s;
}
}
public class creator{
public string email;
public string displayName;
public string self;
}
public class start{
public string datetimew;
}
除了上面字符串中的日期时间之外,我可以从中获取所有数据。由于 datetime 是 apex 中的保留关键字,因此我无法在我的班级中将变量名称作为 datetime 。
任何建议!
Json 解析器代码:
JSONParser parser = JSON.createParser(jsonData );
while (parser.nextToken() != null) {
// Start at the array of invoices.
if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
while (parser.nextToken() != null) {
// Advance to the start object marker to
// find next invoice statement object.
if (parser.getCurrentToken() == JSONToken.START_OBJECT) {
// Read entire invoice object, including its array of line items.
wrapGoogleData inv = (wrapGoogleData)parser.readValueAs(wrapGoogleData.class);
String s = JSON.serialize(inv);
system.debug('Serialized invoice: ' + s);
// Skip the child start array and start object markers.
//parser.skipChildren();
lstwrap.put(inv.id,inv);
}
}
}
}