2013-08-08 4 views
1

내가 이런 JSON 파일 가지고와다차원 배열 json_decode (제 1 레벨)

{ 
    "numeric1": { 
     "id": "numeric1", 
     "name": "alphanumeric1", 
     "key": "alphanumeric2", 
     "expire": "alphanumeric3", 
     "status": true, 
     "ads": true 
    }, 

    etc... 
} 

을 (등) I는 행렬 회 이상 반복되는 것을 의미한다.

같이 배열 그리고
$allowed = json_decode(file_get_contents("allowed.json"), true); 

내가 얻을 : 나는

 [0] => Array
대신
 ["numeric1"] => Array

어떻게 내가 연관 키의 첫 번째 수준을 잃게 그래서

Array 
(
    [0] => Array 
     (
      [id] => numeric1 
      [name] => alphanumeric1 
      [key] => alphanumeric2 
      [expire] => alphanumeric3 
      [status] => 1 
      [ads] => 1 
     ) 

    etc.... 
) 

이 내가 사용하는 PHP로 구문 분석 내 JSON 배열의 첫 번째 수준을 유지할 수 있습니까? 감사.

+0

JSON 예제에 두 번째 요소를 표시 할 수 있습니까? 그 요소는'numeric2'의 속성 값을 가질까요? –

+0

예 "numeric2", 다음 "numeric3"등 – PurpleFoxy

답변

2

이 시도 :

$allowed = (array) json_decode(file_get_contents("allowed.json")); 

을 그래서 그 대신 직접 배열로 JSON을 파싱 (json_decode의 두 번째 매개 변수를 지정하여), 먼저 키를 보존하는 오브젝트를 얻을, 다음 배열로 캐스팅.

+0

그것은 고마워요! – PurpleFoxy