Hi there I was wondering if somebody could help me?
I have the following code. It retrieves JSON data from a php file. The Json is the following format :
{"Title":"rose","Price":1.25,"Number":15},{"Title":"daisy","Price":0.75,"Number":25},{"Title":"orchid","Price":1.15,"Number":7}
This JSON is created using the following php code:
$shop = array();
$shop = array( array( Title => "rose",
Price => 1.25,
Number => 15
),
array( Title => "daisy",
Price => 0.75,
Number => 25,
),
array( Title => "orchid",
Price => 1.15,
Number => 7
)
);
echo json_encode($shop);
Whenever i try and access the data using obj.Title I get an undefined message.
$.ajax({
type: "GET",
url: "data.php",
success: jsonDo
});
//JSON DATA = {"Title":"rose","Price":1.25,"Number":15},{"Title":"daisy","Price":0.75,"Number":25},{"Title":"orchid","Price":1.15,"Number":7}
function jsonDo(data) {
var obj = jQuery.parseJSON(data);
alert(obj.Title)
}
I was wondering how I can access the keys in the JSON and display the data?
Thanks a million.
datais already a JS object. Tryalert(data.Title);