我正在尝试编写服务调用,我认为这是旧方法,我只是在这里给出代码和响应
$list_array[]=array("kotno" => $data_order_rec['KotNo'],"table" => $table,"Printername" => $print_name1,"count" => $cnt,"order_type" => $ordertype,"products" => $products,"items" => $prod_cnt);
echo json_encode(array("meta"=>"200","server_current_time"=>date("Y-m-d H:i:s"),"response"=>array("success"=>"Y","totRec"=>$tot_cnt,"ListValues"=>$list_array)));
{"meta":"200","server_current_time":"2017-07-05 05:33:31","response":{"success":"Y","totRec":11,"ListValues":[{"kotno":"2","table":"AC","Printername":"PR3150","count":1,"order_type":"Dinning","products":"Chic Bl Masala\t\t\t 1\nChckn 777\t\t\t 1\n","items":2},{"kotno":"2","table":"AC","Printername":"RP3150","count":1,"order_type":"Dinning","products":"Fish Masal\t\t\t 1\n","items":4},{"kotno":"2","table":"AC","Printername":"RP3150","count":1,"order_type":"Dinning","products":"Baby Corn Chilly\t\t 1\nChanna Fry\t\t\t 1\n","items":2},{"kotno":"2","table":"AC","Printername":"RP3150","count":1,"order_type":"Dinning","products":"7 Up\t\t\t\t 1\nCoke\t\t\t\t 1\nKulfi Pot\t\t\t 1\n","items":3},{"kotno":"2","table":"AC","Printername":"RP3150","count":1,"order_type":"Dinning","products":"Fish Chilly\t\t\t 1\nFish Daba\t\t\t 1\nFish Manjurian\t\t\t 1\n","items":4}]}}
function getJcontentsURL($jsonurl){
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json,true);
return $json_output; }
$json_url = "http://restaurant.sansoftwareindia.com/api/order_print.php?id=".$_GET['id']."&branch=".$_GET['branch']."&div=".$_GET['div'];
$resJson = getJcontentsURL($json_url);
$num_records = $resJson['response']['totRec']; // Error in this line
错误:不能将字符串偏移量用作数组 第13行的D:\ xampp \ htdocs \ clients \ print \ index.php
我想做什么?
我也尝试这样
$i=0;
foreach ( $entries as $resJson ) {
$info = array(); // added to see if pre-declaration helps
if (is_array($e)) // only go on if $e is actually an array
$info = array( $e[ 'server_current_time' ],
$e[ 'response' ][ 'success' ],
$e[ 'response' ][ 'totRec' ],
$e[ 'response' ][ 'ListValues' ][$i][ 'Printername' ] );
$i++;
}
print_r($info);
基于"Cannot use string offset as an array" error
这不会返回任何值