Code example for JsonParser

Methods: parse

0
 
public class JsonAccessorTestCase extends BaseTestCase { 
    protected final static Logger logger = Logger.getLogger(UtilTestCase.class); 
	 
    public void testJsonAccessor() { 
    	JsonParser parser = new JsonParser(); 
    	JsonElement json = parser.parse("{firstName: 'Kelven', lastName: 'Yang', arrayObj: [{name: 'elem1'}, {name: 'elem2'}]}");
    	JsonAccessor jsonAccessor = new JsonAccessor(json);
    	 
    	Assert.assertTrue("Kelven".equals(jsonAccessor.getAsString("firstName")));
    	Assert.assertTrue("Kelven".equals(jsonAccessor.getAsString("this.firstName")));
    	Assert.assertTrue("Yang".equals(jsonAccessor.getAsString("lastName")));
    	Assert.assertTrue("Yang".equals(jsonAccessor.getAsString("this.lastName")));
    	 
    	Assert.assertTrue("elem1".equals(jsonAccessor.getAsString("arrayObj[0].name")));
    	Assert.assertTrue("elem2".equals(jsonAccessor.getAsString("arrayObj[1].name")));
    	 
    	Assert.assertTrue("elem1".equals(jsonAccessor.getAsString("this.arrayObj.this[0].name")));
    	Assert.assertTrue("elem2".equals(jsonAccessor.getAsString("this.arrayObj.this[1].name")));
    	 
Connect your IDE to all the code out there  Get Codota for Java