Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a JSON return by a PHP request. The result is:

{"serials":
      {"4":
          [{"serial":"15990"},{"serial":"16536"}],
      "16":
          [{"serial":"13841"}]
       }
}

Could you please explain me how to read each serial value to show them on html

Kind regards

share|improve this question

2 Answers 2

You can iterate over serials using this code:

for (var key in json.serials) {
   for (var i=0; i<json.serials[key].length; ++i) {
       json.serials[key][i].serial;// invidual serial
   }
}
share|improve this answer
    
Works also thanks!! –  llaid 21 hours ago
    
must have use document.write @jcubic ? –  llaid 21 hours ago
var return_data = {"serials":
              {"4":
                  [{"serial":"15990"},{"serial":"16536"}],
              "16":
                  [{"serial":"13841"}]
               }
        };

        for (var index in return_data['serials']) {

            var data = return_data['serials'][index];

            for (var i = 0; i < data.length; i++) {
                document.write('<p>' + data[i].serial + '</p>');

            };

        }
share|improve this answer
    
Thanks a lot guys!! –  llaid 21 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.