-2

I don't know php at all and try to rewrite an example of using php with android

I want my android app to send some data - name and message and receive list of this data as JSON

now - what I have from my example :

<?php

    // Get Post Data
    $data = urldecode($_POST['data']);
    $name = urldecode($_POST['name']);

    $jsonData      = array();
    $jsonTempData  = array();


          $jsonTempData = array();
          $jsonTempData['name']         = $name;
          $jsonTempData['number']       = $data;
          $jsonTempData['date_added']   = // I don't know how to set date

          $jsonData[] = $jsonTempData;


     $outputArr = array();
     $outputArr['Android'] = $jsonData;

     // Encode Array To JSON Data
     print_r( json_encode($outputArr));


 ?>

which means I send some data and get it back in one method which is , I assume, wrong. how can I separate them - sending data to php and receiving json.i have to repeat, I got zero knowledge in php.

Plus it's only one name-message pair wrapped into array and what I need is to make array of this messages and return them in JSON.Oh, and I need to write time of message into array

thank you

4

1 回答 1

1
$jsonTempData['date_added']   = date('Y-m-d');//To set date

如果您想要各种日期格式,请查看手册

如果您想返回 json 数据,只需执行此操作(如果您使用的是函数,则只能返回一个值。)

return json_encode($outputArr);

如果你想显示它

echo json_encode($outputArr);
于 2013-08-26T11:46:14.067 回答