1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
■JSON解析 -------------- <JS> ● OBJ→JSON:JSON.stringify(obj) ● OBJ→JSON:JSON.stringify(obj) ● JSON→OBJ:JSON.parse(string) ● OBJ→JSON→OBJ:JSON.parse(JSON.stringify(obj)); <APEX> ● OBJ→JSON:JSON.deserializ(string, class) <APEX list> ● LIST<OBJ>→JSON:JSON.serialize(data) ● JSON→LIST<OBJ>:JSON.deserializ(string, List.class) ● LIST<OBJ>→JSON→LIST<OBJ>:JSON.deserialize(JSON.serialize(data),List.class) <Apex JSON解析> ● OBJ→JSON:JSON.createParser https://developer.salesforce.com/docs/atlas.ja-jp.apexcode.meta/apexcode/apex_json_jsonparser.htm JSONParser parser = JSON.createParser(response.getBody()); OR JSONParser parser = JSON.createParser(resultObj.toSFJsonString()); ・JS to Apex ★String化 <JSON→string:JSON.stringify(class)> fetchCmtLotList({ serializedCmtPvcTyp: JSON.stringify(event.detail) }) .then(result => { }); ・Apex ★Stringで受け取る,JSON化する <String→JSON:JSON.deserializ(string, class)> public static List<CMT_PartitionValueCalculation__c> fetchCmtPvcList(String serializedCmtPvcTyp){ CMT_PartitionValueCalculation__c cmtPvcTyp = (CMT_PartitionValueCalculation__c)JSON.deserialize(serializedCmtPvcTyp,CMT_PartitionValueCalculation__c.class); } -------------- ・JS to Apex ★JSON化しない /** * inline編集(複数行) */ async handleSave(event) { const updatedFields = event.detail.draftValues; // Prepare the record IDs for getRecordNotifyChange() const notifyChangeIds = updatedFields.map(row => { return { "recordId": row.Id } }); // Pass edited fields to the updateContacts Apex controller await updateLots({ data: updatedFields }) .then(result => { }); ・Apex ★JSONする <String→JSON:JSON.deserializ(string, class)> <JSON→string:JSON.stringify(class)> List<CMT_LotCalculation__c> lotsForUpdate = (List<CMT_LotCalculation__c>) JSON.deserialize( JSON.serialize(data), List<CMT_LotCalculation__c>.class ); ・Apex to JS ★JSONする <JSON→string:JSON.stringify(class)> <String→JSON:JSON.parse(string)> createRecord(recordInput) .then((result) => { const retAccount = JSON.parse(JSON.stringify(result)); |