You need to sign in to do that
Don't have an account?

Parsing JSON into Salesforce objects
I'm having trouble wrapping my head around the json parser, and getting it work to a fairly simple JSON string.
{
"Object1":[{"id":1,"name":"SomeName"}],
"Object2":[{"id":1,"location":"SomeLocation"}]
}
Basically, I'd like to parse through the JSON and seperate the two objects and display some of the attributes on a visualforce page. If I create two classes like so:
public class Object1 {
public Integer id;
public String name;
}
public class Object2 {
public Integer id;
public String location;
}
How can I run through the Json and create an instance of each class?
{
"Object1":[{"id":1,"name":"SomeName"}],
"Object2":[{"id":1,"location":"SomeLocation"}]
}
Basically, I'd like to parse through the JSON and seperate the two objects and display some of the attributes on a visualforce page. If I create two classes like so:
public class Object1 {
public Integer id;
public String name;
}
public class Object2 {
public Integer id;
public String location;
}
How can I run through the Json and create an instance of each class?
public class JSON2Apex {
public class Object1 {
public Integer id;
public String name;
}
public class Object2 {
public Integer id;
public String location;
}
public List<Object1> Object1;
public List<Object2> Object2;
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
}
But, how can I invoke this manually and display the results of each list on a visualforce page?