Firstly, I am extremely new to JSON. I have been reading as much as I can on it. While I get the concept, implementing it is a different deal altogether for me.
So, I have an app which reads and displays data from JSON web pages. For instance, I can extract the time that is being shown in this website: http://date.jsontest.com/
Using the HTML from this website, I added the JSON Object to my HTML page in the following manner:
<html>
<body>
<pre>
{
"score": "30-20"
}
</pre>
</body>
</html>
However, the app now throws a JSON exception everytime I try to retreive the score.
My question is, 'Is adding a JSON Object to the pre tag in an HTML page the correct way of creating a JSON Object on a web page?'
If not, what is the correct way to do it?
EDIT: This is is the code I am using in java to retrieve the JSON data:
StringBuilder url = new StringBuilder(URL);
HttpGet get = new HttpGet(url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if(status==200){
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
//JSONArray timeline = new JSONArray(0);
JSONObject last = new JSONObject(data);
return last;
}
else{
Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
return null;
}
The try statement:
try {
json = lastTweet();
return json.getString("time");
//return "Oh Well";
}
Thanks.