PHP разбирает JSON из массива - PullRequest
0 голосов
/ 23 марта 2012

Я пытаюсь извлечь ключ (Status) из массива, отформатированного с помощью json.

Массив

Array ( [0] => Running correlate.sh [1] => /var/www/html/blah/Correlation/classes [2] => Executing java command with JSON pps null 93993939 John Smith John Smith 1234 M 01-1-1990 [3] => last name is SMITH [4] => configFilePath is null [5] => feedName is pps [6] => [7] => select distinct(null), guid , scx_eid, emplid, national_ID, last_name, birthdate, first_name from table_a where guid is not null and ( scx_eid = '12345678' or emplid = 'null' or (substr(national_ID,length(national_ID)-3,4) = '1234' and upper(last_name) = 'SMITH') or (substr(national_ID, length(national_ID)-3,4) = '1234' and birthdate = '90-null-01-1') or (birthdate = '90-null-01-1' and upper(last_name) = 'SMITH') or (upper(first_name) = 'JOHN' and upper(last_name) = 'ZSCHEILE')) [8] => first match {} [9] => [10] => select distinct(null), guid , eid, last4ssn, lastname, dob, firstname from table_c where guid is not null and ( eid = '12345678' or (substr(last4ssn,length(last4ssn)-3,4) = '1234' and upper(lastname) = 'SMITH') or (substr(last4ssn, length(last4ssn)-3,4) = '1234' and dob = '90-null-01-1') or (dob = '90-null-01-1' and upper(lastname) = 'SMITH') or (upper(firstname) = 'JOHN' and upper(lastname) = 'SMITH')) [11] => second match {} [12] => [13] => select distinct(null), guid , eid, emplid from table_d where guid is not null and ( eid = '12345678' or emplid = 'null') [14] => third match {} [15] => ldapMatch list is null [16] => returning firstMatch as {} [17] => [18] => Final Status:{Status=DISPUTED, GUID=[]} [19] => {"Status":"DISPUTED","GUID":[]}exiting script )

Что мне нужно

$status = 'DISPUTED';

Обновление

Мне удалось изменить Java, поэтому он выводит это ниже. Как я могу разобрать это, чтобы получить две переменные, $ status и $ GUID?

{"Status":"DISPUTED","GUID":[]}
{"Status":"CONFIRMED","GUID":[G010908712]}
{"Status":"DISPUTED","GUID":[]}
{"Status":"DISPUTED","GUID":[]}
{"Status":"CONFIRMED","GUID":[G403057017]}
{"Status":"CONFIRMED","GUID":[G104522939]}
{"Status":"CONFIRMED","GUID":[G020669940]}

1 Ответ

1 голос
/ 23 марта 2012

Если строка exiting script действительно находится в конце вашего JSON, это все испортит.В противном случае json_decode принимает второй аргумент, чтобы указать, что вы хотите массив, а не объект:

$json_a = json_decode($array[19], true);
...