0

This is my 3rd jquery script and I'm not sure what I'm doing.

I want to read multiple json values from 3 different queries. My JSON is returning what I was expecting:

key
 1    ["value1"]
 2    ["value2"]
max   2101
total 22

I can read the first two values using somethin like this:

  ajax(                                      
   url: 'api.php, data: "", dataType: 'json',  success: function(rows)        
    { 
      for (var i in rows)
      {
        var row = rows[i];
        value1 = row[0];
      }

How can I read the max value from the JSON? I tried thing like:

 $row[max], $row['max'], etc.

I'm reading the values with JavaScript

Thanks

2
  • It's unclear which technology are you are using to read these values? Javascript or PHP? I assume Javascript. Commented Jul 18, 2012 at 17:17
  • 1
    Have you tried just rows.max? I'm not sure what you're expecting $row to be as it's not defined anywhere in your given code Commented Jul 18, 2012 at 17:17

2 Answers 2

1

row.max might be what you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

0

Try using javascript's eval function in your success handler. It will convert your returned json text into a javascript object which you can then manipulate. Something like:

success: function(data) {
         var returned_array = eval(data);

         //access values as if it were a regular javascript object
         alert(returned_array['max']);
         //OR
         alert(returned_array.max);
       }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.