Skip to main content
sandeep reddy a posé une question dans #Integration
i write programe about transforing data from json to class the code is 

public class jsonclass {

    public string result{set;get;}

    public jsonclass(){

              string jso ='{"name":"suriprakesh","age":20,"salary":20000}';

    map<string,list<string>> m = (map<string,list<string>>)JSON.deserializeuntyped(jso);

        }

    

    }

       its getting run time error that is just tell me please  
1 réponse
  1. 28 avr. 2016, 13:03
    PLease check below post to convert JSON to Apex

    1) https://www.adminbooster.com/tool/json2apex

    Please try below code

    //

    //Generated by AdminBooster

    //

    public class fromJSON{

    public String name; //suriprakesh

    public Integer age; //20

    public Integer salary; //20000

    public static fromJSON parse(String json){

    return (fromJSON) System.JSON.deserialize(json, fromJSON.class);

    }

    static testMethod void testParse() {

    String json= '{"name":"suriprakesh","age":20,"salary":20000}';

    fromJSON obj = parse(json);

    System.assert(obj != null);

    }

    }

    Please try below code.

    public class jsonclass

    {

    public string result{set;get;}

    public jsonclass()

    {

    String json='{"name":"suriprakesh","age":20,"salary":20000}';

    fromJSON obj = parse(json);

    }

    public class fromJSON

    {

    public String name; //suriprakesh

    public Integer age; //20

    public Integer salary; //20000

    public static fromJSON parse(String json){

    return (fromJSON) System.JSON.deserialize(json, fromJSON.class);

    }

    }

    }

    For more information on REST class please check below post

    1) http://amitsalesforce.blogspot.in/search/label/Rest%20API

    Let us know if this will help you

    Thanks

    Amit Chaudhary