Created
September 19, 2017 03:35
-
-
Save shinsaka/bbbbb693ff24ba368e17605e18adbd8f to your computer and use it in GitHub Desktop.
using JSONGenerator with Apex/SFDC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hoge p = new Hoge(); | |
p.code = '0001'; | |
p.name = 'hogename1'; | |
p.items = new List<HogeItem>{ | |
new HogeItem('0001-01', 'item001'), | |
new HogeItem('0001-02', 'item002') | |
}; | |
JSONGenerator jg = JSON.createGenerator(false); | |
jg.writeObject(p); | |
System.debug(jg.getAsString()); | |
public class Hoge { | |
public String code; | |
public String name; | |
public List<HogeItem> items; | |
} | |
public class HogeItem { | |
public String itemcode; | |
public String itemname; | |
public HogeItem(String code, String name) { | |
this.itemcode = code; | |
this.itemname = name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment