2016-07-29 119 views
-1

我有一个php脚本,在我的android应用程序的json中给出响应。在json中添加响应代码

的JSON:

{"0":"1","id":"1","1":"mahmudul hasan","name":"mahmudul hasan","2":"364","roll":"364","3":"sohel","qrcode":"sohel"} 

,但我也想与resonse象下面这样的状态:

{ 
    "0": "1", 
    "1": "mahmudul hasan", 
    "2": "364", 
    "3": "sohel", 
    "id": "1", 
    "name": "mahmudul hasan", 
    "roll": "364", 
    "qrcode": "sohel", 
    **"success": true** 
} 

我的JSON响应PHP男女同校:

foreach ($data as $item) 
    { 
     if($item!=NULL) 
     { 
      echo json_encode($item); 
     } 
     else 
     { 
      echo json_encode($item);    
     } 
    } 

应该如何我添加响应状态?

回答

1

尝试这样的事情

foreach($data as $item) { 

    $item['status'] = false; 

    if (isset($item) && is_array($item)) { 
     $item['status'] = true; 
    } 

    echo json_encode($item); 
} 
从这个

除了你为什么不能尝试: -

foreach ($data as $key => $item) { 
    if (is_array($item) && count($item) > 0) { 
     $data[$key]['status'] = true; 
    } else { 
     //unset($data[$key]) 
     $data[$key]['status'] = false; 
    } 
} 
echo json_encode($data); 
+0

让我查一下。这是真的吗? –

+0

@ sohel14_cse_ju编辑回答 –

+0

我可以返回空JSON没有数据匹配吗? –