function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aviator517Aviator517 

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?
Aviator517Aviator517
The json2apex heroku app (http://json2apex.herokuapp.com) spits out something like this:

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?