json - Getting information from array of array -


i've tried getting information json 1 function, , works fine. when becomes 2 or more though pointed out array of array should used.

how can decode information?

get.php

$response = array("home"=>$home, "topr"=>$top); echo json_encode($response); 

test.js

$(document).ready(function() {      $.get("php/get_ratings.php")     .done(function(data) {         var results = jquery.parsejson(data); // should change this?          $.each(results, function(i, value) { // or this?         })     }); }); 

what php calls "arrays" not languages call "arrays," including both json , javascript. response in form:

{"home": something, "topr": something} 

in code:

  1. no, don't need parse it, jquery if it's being sent correctly (e.g., content-type: application/json).

  2. you can access .homeand .topr properties on object receive.

e.g.:

$( document ).ready(function() {      $.get( "php/get_ratings.php")     .done(function(data) {           // use data.home , data.topr here     });  }); 

what them depends on are, haven't shown. if they're numerically-index arrays (what languages call arrays), response this:

{"home":["stuff","here"], "topr": ["stuff","here"]} 

...and .home , .topr javascript arrays.

if they're php associative arrays top level thing, they'll come through objects, properties named after keys of associative array.


Comments