0

適切にフォーマットされたjson文字列に問題があると思います。クエリ文字列の作成によるものかどうか疑問に思っていますが、以下のエンコードされたjson文字列にある二重角かっこに問題がない限り、私には正しく見えます。余分な目を探しています。

jsonエンコーディングの前は、var_dump($ ConsiderationCodes)は次のようになります。

array (size=2)
  8 => 
    array (size=13)
      67 => 
        array (size=1)
          0 => 
            array (size=3)
              ...
      41 => 
        array (size=1)
          0 => 
            array (size=3)
              ...
      42 => 
        array (size=1)
          0 => 
            array (size=3)
              ...

印刷json_encode($ ConsiderationCodes); 次のようになります:

$considerationCodes = 
{"8": {"67":  [[  {"id":"64","description":"string description..."},{"id":"65","description":"string description..., "},{"id":"66","description":"string description..."}  ]]  , "41":  [[  {"id":"64","description":"string description..."},{"id":"65","description":"string description..., "},{"id":"66","description":"string description..."}  ]] }}  

Jsonは、それがどのように期待/受け入れられるかを構造化します(テストされ、生データで機能します):

['8']['67']['64'] = "string description...";
['8']['67']['65'] = "string description...";
['8']['67']['66'] = "string description...";
['8']['41']['64'] = "string description...";
['8']['41’]['65'] = "string description...";
['8']['41']['66'] = "string description...";
...etc

そして、これは私がjsonエンコードを送信する方法です(テストされ、生データで動作します):

return $this->renderText(json_encode( $considerationCodes[$appCode][$reasonCode] ) ); 

このjson送信(複数選択選択入力)の結果を見ると、次のようになります。

[Object][object][Object][object][Object][object][Object][object]

私は何が欠けていますか?

編集:

これが私のアレイの構築方法です。

$reason_codes_ids = array();
        foreach($all_reason_codes as $key => $values) {
            $reason_codes_ids[] = $values['id'];
        }
        //wrap the consideration_info into each reason_id:        
        $codes_with_reasons = array();
        foreach($reason_codes_ids as $value){
            foreach($consideration_info as $key => $value1){
                $codes_with_reasons[$value][$key] = $value1;
            }
        }
        //the above results in: ['reason-code-id']['consideration-code-id'] = "consideration-code-answer":
        //next, get the declined_app_status:
        $declinedAppStatus = 8;
        //then wrap the above results in a wraper for the declined application-code
        $declinedConsiderationCodes = array();
        foreach($codes_with_reasons as $key => $value)
        {
            $declinedConsiderationCodes[$declinedAppStatus][$key]=[$value];
        }
        $considerationCodes = $declinedConsiderationCodes;

と:

$consideration_info =

array (size=3)
  0 => 
    array (size=2)
      'id' => string '64' (length=2)
      'description' => string 'string...' (length=35)
  1 => 
    array (size=2)
      'id' => string '65' (length=2)
      'description' => string ''string...' (length=143)
  2 => 
    array (size=2)
      'id' => string '66' (length=2)
      'description' => string ''string...' (length=143)

$reason_codes_ids =

array (size=13)
  0 => string '67' (length=2)
  1 => string '41' (length=2)
  2 => string '42' (length=2)
  3 => string '43' (length=2)
  4 => string '44' (length=2)
  5 => string '45' (length=2)
  6 => string '46' (length=2)
  7 => string '47' (length=2)
  8 => string '48' (length=2)
  9 => string '49' (length=2)
  10 => string '50' (length=2)
  11 => string '51' (length=2)
  12 => string '68' (length=2)
4

1 に答える 1

0

適切なフォーマットとインデントを使用すると、JSON文字列は次のようになります。

{
    "8": {
        "67": [
            [
                {
                    "id":"64",
                    "description":"string description..."
                },
                {
                    "id":"65",
                    "description":"string description..., "
                },
                {
                    "id":"66",
                    "description":"string description..."
                }
            ]
        ],
        "41": [
            [
                {
                    "id":"64",
                    "description":"string description..."
                },
                {
                    "id":"65",
                    "description":"string description..., "
                },
                {
                    "id":"66",
                    "description":"string description..."
                }
            ]
        ]
    }
}

['8']['67']は数値インデックスを持つ配列であることに注意してください。やりたいようにするには、JSON文字列を次のようにする必要があります:(サンプル

{
    "8": {
        "67": {
            "64":"string description...",
            "65":"string description..., ",
            "66":"string description..."
        },
        "41": {
            "64":"string description...",
            "65":"string description..., ",
            "66":"string description..."
        }
    }
}

したがって、PHP配列は次のようになります。

$considerationCodes = array(
    "8" => array(
        "67" => array(
            "64" => "string description...",
            "65" => "string description..., ",
            "66" => "string description..."
        ),
        "41" => array(
            "64" => "string description...",
            "65" => "string description..., ",
            "66" => "string description..."
        )
    )
);
于 2012-09-20T20:17:56.977 に答える