1

i am using this tutorial

please guide me how can i customized it for my mysql table which is like this enter image description here

i am unable to understand how to get this sort of out from my table .

 {"earthquakes": [
        {
            "eqid": "c0001xgp",
            "magnitude": 8.8,
            "lng": 142.369,
            "src": "us",
            "datetime": "2011-03-11 04:46:23",
            "depth": 24.4,
            "lat": 38.322
      },
      {
            "eqid": "2007hear",
            "magnitude": 8.4,
            "lng": 101.3815,
            "src": "us",
            "datetime": "2007-09-12 09:10:26",
            "depth": 30,
            "lat": -4.5172
      }
    <--more -->
    ]}

i am using php . Thanks

8
  • The question is not clear, what do you want to do, exactly? Getting the data from your database and giving a JSON format? Commented Apr 28, 2011 at 20:12
  • i have tried it with this while($arr=mysql_fetch_assoc($q)) $res[]=$arr; print(json_encode($res)); Commented Apr 28, 2011 at 20:13
  • @Cristian yes like stated in the tutorial Commented Apr 28, 2011 at 20:17
  • What you're doing looks fine, it should create an array of objects similar to the example. But it wont follow the exact same structure. In the example its an object with a field "earthquakes" which is an array of objects. In your code, it'll be just an array of objects. Commented Apr 28, 2011 at 20:33
  • 1
    I meant $jobj[sample]=$arr; echo json_encode($jobj); Commented Apr 28, 2011 at 20:40

2 Answers 2

2

That tutorial shows how to consume JSON in the android client.

Try some of these tutorials for the server side part of the equation:

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

Comments

1

This is the documentation for json_encode

http://php.net/manual/en/function.json-encode.php

and also see if these examples help:

http://www.sencha.com/learn/Tutorial%3aCreating_JSON_Data_in_PHP

http://davidwalsh.name/web-service-php-mysql-xml-json

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.