If the JSON object is being returned as part of an Ajax request you'll need something vaguely like this:
$.post("yourajaxrequest.php", //calls .php file and transmits data via $_POST
{
//variables required by the PHP file go here
},
//the function to perform when an object is returned from .php file
function(toreceive){
var obj = JSON.parse(toreceive);
var first = obj.returnone;
});
Without reading the Yelp documentation I'm not sure quite how you'll receive the object from Yelp, but the JSON.parse()
method is the approach you should take to decode the object.
After parsing the object to a variable, you can assign the elements of the object by calling object.*insert array value here*;
This would be declared in PHP normally with something similar to:
$toencode = "The first string to be encoded";
$tosend['returnone'] = $toencode;
echo json_encode($tosend);
exit;
You can then append to a <ul>
by using .append
<html>
<head>
</head>
<body>
<ul id="list">
</ul>
</body>
</html>
In your <script>
:
$('#list').append('<li>'+first+'</li>');
Without any sample code or reading the Yelp documentation, there's not a lot more to go on.
Hope it helps.
**edited to add closing bracket and semi-colon to first line of code.