how to use json_decode() method for this complex json object?particular i want to get value of x and value of y.
{"list":{"num":"11","type":"map"},"tagName":"resultset","childList":[{"list":{"addr":"Delhi","type":"exact","z":"3","y":"28.6327","x":"77.2197"},"tagName":"result","childList":[]},{"list":{"addr":"Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Deoli,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Pur > Delhi,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Sabhaypur > Delhi,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Chirag > Delhi,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Delhi > Tyre Delhi,Kilokri,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"New > Delhi > District,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Babarpur,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]},{"list":{"addr":"Barwala,New > Delhi,Delhi","type":"alternate"},"tagName":"result","childList":[]}]}
here is array object
Array > Array ( [list] => Array ( [num] => 11 [type] => map ) [tagName] => > resultset [childList] => Array ( [0] => Array ( [list] => Array ( > [addr] => Delhi [type] => exact [z] => 3 [y] => 28.6327 [x] => 77.2197 > ) [tagName] => result [childList] => Array ( ) ) [1] => Array ( [list] > => Array ( [addr] => Delhi [type] => alternate ) [tagName] => result [childList] => Array ( ) ) [2] => Array ( [list] => Array ( [addr] => > Deoli,New Delhi,Delhi [type] => alternate ) [tagName] => result > [childList] => Array ( ) ) [3] => Array ( [list] => Array ( [addr] => > Pur Delhi,New Delhi,Delhi [type] => alternate ) [tagName] => result > [childList] => Array ( ) ) [4] => Array ( [list] => Array ( [addr] => > Sabhaypur Delhi,New Delhi,Delhi [type] => alternate ) [tagName] => > result [childList] => Array ( ) ) [5] => Array ( [list] => Array ( > [addr] => Chirag Delhi,New Delhi,Delhi [type] => alternate ) [tagName] > => result [childList] => Array ( ) ) [6] => Array ( [list] => Array ( [addr] => Delhi Tyre Delhi,Kilokri,New Delhi,Delhi [type] => alternate > ) [tagName] => result [childList] => Array ( ) ) [7] => Array ( [list] > => Array ( [addr] => New Delhi,Delhi [type] => alternate ) [tagName] => result [childList] => Array ( ) ) [8] => Array ( [list] => Array ( [addr] => New Delhi District,Delhi [type] => alternate ) [tagName] => > result [childList] => Array ( ) ) [9] => Array ( [list] => Array ( > [addr] => Babarpur,New Delhi,Delhi [type] => alternate ) [tagName] => > result [childList] => Array ( ) ) [10] => Array ( [list] => Array ( > [addr] => Barwala,New Delhi,Delhi [type] => alternate ) [tagName] => > result [childList] => Array ( ) ) ) )
If you are using jQuerys ajax, then you can access the response in the success method like so: (assuming you're doing a GET)
$.ajax({
type: "GET",
url: "myphp.php",
success: function() {
var x = resp.childList[0].list.x;
var y = resp.childList[0].list.y;
$('#result').html('X: ' + x + 'Y: ' + y);
}
});
Please see this on how to use jQuerys ajax with PHP. http://iviewsource.com/codingtutorials/learning-how-to-use-jquery-ajax-with-php-video-tutorial/
i got x and y like this i am able to save my json response in html div like this.:-)
function StartAjax(ResultsId){
$.ajax({
type: "GET",
url: "myphp.php",
cache: false,
success: function (data) {
data=eval("("+data+")");
for (var x = 0; x < data.childList.length; x++) {
if(data.childList[x].list.type=='exact')
{
y=data.childList[x].list.x;
k=data.childList[x].list.y;
}
)};
</script>
</head>
<body>
<a href="#" onclick="StartAjax('ResultsId');">Click Here to see content from myphp.php</a>
<div id="ResultsId"></div>