创建PHP Web服务以JSON格式响应android应用程序


Create PHP webservice to respond to android Application in JSON format

以前我使用restful wcf Web服务从服务器获取数据。但现在我必须访问PHP Web服务。使用WCF restful Web服务,我曾将数据获取为:

{ 
1,books, //0th index  
2,toys,  //1st index . . .
}

但是当我从php-webservice获取数据时,它是一个类似于下面格式的单个数组

[
1,            // 0th index
books,        // 1st index
2,            // 2nd index
toys,         // 3nd index
.
.
.
]

请告诉我,在php中创建json数组是不可能的,因为它是在WCF restful服务中创建的??上面显示的格式只是我从Web服务中获得的实际数据的符号表示。

php开发人员使用Joomla 1.7.3和virtualmart 2.0来开发web服务,并且web应用程序仅使用1.7.3和Virtualmart 2.0创建。

您需要根据需要修改数组的维度,我想是这样的:

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

此代码将返回索引值:

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

这里有一个Android/PHP Web服务的好例子。