Shruti
Shruti

Reputation: 5591

Create PHP webservice to respond to android Application in JSON format

Previously i have used restful wcf webservices to get the data from server.But now i have to access PHP webservices.Using WCF restful webservices I used to get data as :

{ 

1,books, //0th index  

2,toys,  //1st index . . .

}

but wen i am getting data from php webservice it is coming as a single array similar to the format shown below

[

1,            // 0th index

books,        // 1st index

2,            // 2nd index

toys,         // 3nd index

.

.

.

]

Please tell me is is not possible in php to create a json array as it is created in WCF restful services ?? Above shown formats are only symbolic representation of the actual data what i am getting from webservices.

Joomla 1.7.3 and virtuemart 2.0 is used by php developer to develop webservices and also web app is created in using 1.7.3 and virtuemart 2.0 only.

Upvotes: 0

Views: 3195

Answers (2)

Hiren Dabhi
Hiren Dabhi

Reputation: 3713

Here is a good example of an Android / PHP webservice.

Upvotes: 2

robertboloc
robertboloc

Reputation: 169

you need to modifiy the dimension of the array accordingly to what you want, somthing like this I presume:

$test = array('1' => array('books', 'foo', 'bar'),
              '2' => array('toys', 'foo', 'bar'));

print (json_encode($test));

This code will return the indexed values:

{"1":["books","foo","bar"],"2":["toys","foo","bar"]}

Upvotes: 2

Related Questions