0

This question already has an answer here:

I have the following JSON

[{"Name":"Global Media","Phone":"(905) 555-1212","Id":"0016A0000035QXuQAM","Contacts":[{"AccountId":"0016A0000035QXuQAM","Id":"0036A000002BnDpQAK","LastName":"White","FirstName":"Carole"},{"AccountId":"0016A0000035QXuQAM","Id":"0036A000002BnDqQAK","LastName":"Amos","FirstName":"Jon"},{"AccountId":"0016A0000035QXuQAM","Id":"0036A000002BnDoQAK","LastName":"Minor","FirstName":"Geoff"}]},{"Name":"Acme","Phone":"(212) 555-5555","Id":"0016A0000035QXvQAM","Contacts":[{"AccountId":"0016A0000035QXvQAM","Id":"0036A000002BnDsQAK","LastName":"Jones","FirstName":"Howard"},{"AccountId":"0016A0000035QXvQAM","Id":"0036A000002BnDtQAK","LastName":"Tomlin","FirstName":"Leanne"},{"AccountId":"0016A0000035QXvQAM","Id":"0036A000002BnDrQAK","LastName":"Stamos","FirstName":"Edward"}]},{"Name":"salesforce.com","Phone":"(415) 901-7000","Id":"0016A0000035QXwQAM","Contacts":[{"AccountId":"0016A0000035QXwQAM","Id":"0036A000002BnDuQAK","LastName":"Benioff","FirstName":"Marc"}]},{"Name":"ravi","Phone":"8977007142","Id":"0016A00000AmKRyQAN","Contacts":[{"AccountId":"0016A00000AmKRyQAN","Id":"0036A00000FWoavQAD","LastName":"reddy","FirstName":"Ravikumar"}]},{"Name":"ins","Id":"0016A00000Apv84QAB","Contacts":[{"AccountId":"0016A00000Apv84QAB","Id":"0036A00000FbtK4QAJ","LastName":"arjun"}]},{"Name":"ims","Rating":"Hot","Id":"0016A00000ApBGDQA3","Contacts":[{"AccountId":"0016A00000ApBGDQA3","Id":"0036A00000FbdpaQAB","LastName":"aru"}]},{"Name":"ims1","Id":"0016A00000DHZdGQAX","Contacts":[{"AccountId":"0016A00000DHZdGQAX","Id":"0036A00000FceFPQAZ","LastName":"malli"}]},{"Name":"ims","Phone":"8977007142","Rating":"Hot","Id":"0016A00000ApBGhQAN","Contacts":[{"AccountId":"0016A00000ApBGhQAN","Id":"0036A00000FbdpfQAB","LastName":"Malli"}]}]

How can I deserialize it to Apex ?

marked as duplicate by Oleksandr Berehovskyi, Tushar Sharma, Basti, Mahmood, Raul Dec 19 '17 at 12:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

Use json2apex tool

//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class JSON2Apex {

    public class JSON2Apex {
        public String Name;
        public String Phone;
        public String Id;
        public List<Contacts> Contacts;
        public String Rating;
    }

    public class Contacts {
        public String AccountId;
        public String Id;
        public String LastName;
        public String FirstName;
    }

    public class Contacts_Z {
        public String AccountId;
        public String Id;
        public String LastName;
    }


    public static List<JSON2Apex> parse(String json) {
        return (List<JSON2Apex>) System.JSON.deserialize(json, List<JSON2Apex>.class);
    }
}

and then you can deserialize it in the following way:

List<JSON2Apex> des = JSON2Apex.parse(jsonString);
  • I implimented above code. i m getting following error "Illegal assignment from List<JSON2apex.JSON3apex> to List<JSON2apex>" – Arjun Reddy Dec 19 '17 at 12:19
  • i can able to deserialize now. And also, I want to get that values and insert those values into aacount and contact at the same time. The contacts must related to account. Help me how can i achieve that? – Arjun Reddy Dec 19 '17 at 13:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.