+ Start a Discussion
Mariappan PerumalMariappan Perumal 

Json parsing in apex

Hi Everyone.

 

 

I have written conntroller which will fetch the records from my google analytics account the response i got is in json format.

 

I am unable to parse the json file.

 

Its seems like not a key , value pair format in json.

 

Can anyone assist me on this

 

|{
"kind":"analytics#gaData",
"id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:71511635&dimensions=ga:date&metrics=ga:visitors,ga:newVisits&start-date=2013-04-01&end-date=2013-05-03&max-results=50",
"query":
{
"start-date":"2013-04-01",
"end-date":"2013-05-03",
"ids":"ga:71511635",
"dimensions":"ga:date",
"metrics":["ga:visitors","ga:newVisits"],
"start-index":1,
"max-results":50
},
"itemsPerPage":50,
"totalResults":33,
"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:71511635&dimensions=ga:date&metrics=ga:visitors,ga:newVisits&start-date=2013-04-01&end-date=2013-05-03&max-results=50",
"profileInfo":
{
"profileId":"71511635",
"accountId":"40258520",
"webPropertyId":"UA-40258520-2",
"internalWebPropertyId":"69406345",
"profileName":"All Web Site Data",
"tableId":"ga:71511635"
},
"containsSampledData":false,
"columnHeaders":
[
{
"name":"ga:date",
"columnType":"DIMENSION",
"dataType":"STRING"
},
{
"name":"ga:visitors",
"columnType":"METRIC",
"dataType":"INTEGER"
},
{
"name":"ga:newVisits",
"columnType":"METRIC",
"dataType":"INTEGER"
}],
"totalsForAllResults":
{
"ga:visitors":"31",
"ga:newVisits":"25"
},
"rows":
[
["20130401","0","0"],
["20130402","0","0"],
["20130403","0","0"],
["20130404","0","0"],
["20130405","0","0"],
["20130406","0","0"],
["20130407","0","0"],
["20130408","0","0"],
["20130409","0","0"],
["20130410","0","0"],
["20130411","0","0"],
["20130412","0","0"],
["20130413","0","0"],
["20130414","0","0"],
["20130415","0","0"],
["20130416","0","0"],
["20130417","0","0"],
["20130418","0","0"],
["20130419","5","4"],
["20130420","0","0"],
["20130421","0","0"],
["20130422","1","1"],
["20130423","17","15"],
["20130424","2","1"],
["20130425","2","1"],
["20130426","0","0"],
["20130427","0","0"],
["20130428","0","0"],
["20130429","2","1"],
["20130430","0","0"],
["20130501","0","0"],
["20130502","1","1"],
["20130503","1","1"]
]

 

Thanks in advance
}

Cory CowgillCory Cowgill
Mariappan PerumalMariappan Perumal

Hi Cory Cowgill,

 

Nice to hear from you

 

Yeah am using json apex classes in my controller.

 

I got the response from google analytics and json file is little confusing me.

 

It doesn't seem like json and rows are like 

{

"totalsForAllResults":
{
"ga:visitors":"31",
"ga:newVisits":"25"
},
"rows":
[
["20130401","0","0"],
["20130402","0","0"],
["20130403","0","0"] ]

}

Incase of totalforallresult node we can refer the no of visitors and newvisits through the nodeName ga:visitors and ga:newVisits respectively .

 

But what can we do in case of parsing the rows .

 

Can you please help me out of this. 

 

Thanks in advance