2012-03-23 139 views
-2

我試圖從用json格式化的數組中取出一個鍵(狀態)。PHP從數組解析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因此它輸出低於此。我怎麼能爆炸這個獲得兩個變量,$狀態和$ 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]} 
+0

你會得到什麼結果?你期待什麼結果? – Brian 2012-03-23 18:04:09

+0

沒有設置。我期望$狀態= DISPUTED – Jeffrey 2012-03-23 18:09:28

回答

1

如果字符串exiting script是真的在你的JSON會誤事的結束。否則,json_decode需要第二個參數來指定你想要一個數組,而不是一個對象:

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

是的退出腳本真的在最後 – Jeffrey 2012-03-23 18:18:16

+0

@Jeffrey你需要找出它來自哪裏,然後將其刪除,因爲它使你的JSON無效,所以json_decode無法使用它。如果你願意的話,你可以將它剝離,但這是一個更加棘手的臨時解決方案。如果你真的想解決問題,找出它來自哪裏。 – Paulpro 2012-03-23 18:28:30

+0

我改變了java,以便它返回數組的最後一行爲json。我嘗試了上面的代碼,但它只獲取DISPUTED。 – Jeffrey 2012-03-23 19:17:10