Я пытаюсь проанализировать этот объект JSON и перебрать его, чтобы создать таблицу в формате HTML. На испытаниях я не могу повторить значения. Как мне сделать это правильно?
{"1":{"1":"Employer+EID","2":"File+Creation+Date","3":"File+Creation+Time","4":"Payer+EID","5":"Payer+QID","6":"Payer+Bank+Short+Name","7":"Payer+IBAN","8":"Salary+Year+and+Montd","9":"Total+Salaries","10":"Total+records","11":"","12":"","13":"","14":"","15":""},"2":{"1":"12435800","2":"20160714","3":"0318","4":"12435800","5":"","6":"DBQ","7":"QA79DOHB021104613880010010000","8":"201606","9":"183941.22166664","10":"113","11":"","12":"","13":"","14":"","15":""},"3":{"1":"Record+ID","2":"Employee+QID","3":"Employee+Visa+ID","4":"Employee+Name","5":"Employee+Bank+Short+Name","6":"Employee+Account","7":"Salary+Frequency","8":"Number+of+Working+Days","9":"Net+Salary","10":"Basic+Salary","11":"Extra+hours","12":"Extra+Income","13":"Deductions","14":"Payment+Type","15":"Notes/+Comments"},"4":{"1":"1","2":"27835620341","3":"","4":"SHIJAN+THARAKAN+THOMAS","5":"DBQ","6":"2025","7":"M","8":"30","9":"7300","10":"5000","11":"0.00","12":"2500.00000000","13":"200","14":"","15":""}}
Я старался:
$data = json_decode($_POST['data'],true);
//echo count($data);
echo ($data[4][2]);`
Результатом было null
JSON. Как я могу сделать это правильно?
Ваша строка JSON —
$str = '{"1":{"1":"Employer+EID","2":"File+Creation+Date","3":"File+Creation+Time","4":"Payer+EID","5":"Payer+QID","6":"Payer+Bank+Short+Name","7":"Payer+IBAN","8":"Salary+Year+and+Montd","9":"Total+Salaries","10":"Total+records","11":"","12":"","13":"","14":"","15":""},"2":{"1":"12435800","2":"20160714","3":"0318","4":"12435800","5":"","6":"DBQ","7":"QA79DOHB021104613880010010000","8":"201606","9":"183941.22166664","10":"113","11":"","12":"","13":"","14":"","15":""},"3":{"1":"Record+ID","2":"Employee+QID","3":"Employee+Visa+ID","4":"Employee+Name","5":"Employee+Bank+Short+Name","6":"Employee+Account","7":"Salary+Frequency","8":"Number+of+Working+Days","9":"Net+Salary","10":"Basic+Salary","11":"Extra+hours","12":"Extra+Income","13":"Deductions","14":"Payment+Type","15":"Notes/+Comments"},"4":{"1":"1","2":"27835620341","3":"","4":"SHIJAN+THARAKAN+THOMAS","5":"DBQ","6":"2025","7":"M","8":"30","9":"7300","10":"5000","11":"0.00","12":"2500.00000000","13":"200","14":"","15":""}}';
$result_array = json_decode($str, true);
echo '<pre>'; print_r($result_array);
echo $result_array[4][2];
Он отлично работает для меня. Пожалуйста, проверьте вас $_POST['data']
переменная. Это может не определено отладить эту переменную print_r($_POST);
если это данные Индекс определен, вы увидите индекс данных, таких как —
Array
(
['data'] => 'some_value',
)
Других решений пока нет …