所以我具有以下结构:{“ 3”:“ LT451515”,“ 2”:“ 1222122”,“ 1”:“”}并且我尝试对其进行解码,但是它不起作用。我如何获得单独的数据?
$jsonData = $this->model_account_customer->getCustomerCustomField($this->customer->getId());
//$jsonData is => {"3":"LT451515","2":"1222122","1":""}
$arr = json_decode($jsonData, true);
$data['custom_field_vat'] = $arr[3];
$data['custom_field_company_code'] = $arr[2];
我正在尝试将其打印为PDF,所以没有得到正确的错误,它只是无法打开pdf文件。PDF错误:错误无法加载PDF文档。
您应该执行json_encode这样的操作:
$me = '["11","10","4"]';
$you = json_decode($me);
print_r($you);
现在是一个PHP数组。
Php解码:json_decode
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
var_dump(json_decode($json, true));