0

以前にこの質問を投稿しましたが、誰にとっても簡単にするためにかなりの数のことを明確にする必要がありました. これをJSONで出力しようとしていますが、何もしていないようです...

{
  "request": {
    "act": "user_create",
    "user_email": "newuser@example.com",
    "user_zone": "example.com"
  },
  "result": "success",
  "msg": "A message that will be displayed to the end user"
  ...
}

現在使用しているコードは次のとおりです。

<?php
    $array[0]=array("request"=>array("act"=>'user_create', 
                                     "user_email"=>"newuser@example.com", 
                                     "user_zone"=>"example.com"));
    $array[1]=array('result' => 'success');
    $array[2]=array('msg' => 'A message that will be displayed to the end user');
    echo json_encode($array);
?>

そのコードで、私はこの出力を取得していますが、これは近いですが、それほどではなく、有効な json 出力ではありません。何を変更するかはわかりませんが、現在取得しているものは次のとおりです。

[{"request":{"act":"user_create","user_email":"newuser@example.com","user_zone":"example.com"}},{"result":"success"},{"msg":"A message that will be displayed to the end user"}] 

誰かが私の修正したPHPコードの例を投稿していただければ、それは素晴らしいことです. 過去数時間、さまざまなソリューションをテストして行ったり来たりしてきましたが、必要なものが正確に表示されていないようです:/事前に感謝します!

4

6 に答える 6

2

それで試してみてください..

    $array = array(
    "request" => array(
        "act"=>"user_create",
        "user_email"=>"newuser@example.com",
        "user_zone"=>"example.com"
        ),
    "result"=>"success",
    "msg"=>"A message that will be displayed to the end user"
    );
    echo json_encode($array);
于 2012-10-23T09:24:50.673 に答える
0
$array = array(
"key1" => array(
    "innerkey1"=>"innerkeyvalue1",
    "innerkey2"=>"innerkeyvalue2",
    "innerkey3"=>"innerkeyvalue3"
    ),
"key2"=>"value2",
"key3"=>"value3"
);
echo json_encode($array);

詳細はこちらjsone_encode

于 2012-10-23T18:17:00.230 に答える
0
<?php
    $array["request"]=array("act"=>'user_create', 
                                     "user_email"=>"newuser@example.com", 
                                     "user_zone"=>"example.com");
    $array["result"] = 'success';
    $array["msg"] = 'A message that will be displayed to the end user';
    echo json_encode($array);
?>

これはうまくいくはずです。

于 2012-10-23T09:24:51.863 に答える
0
$array = array(
  "request" => array(
    "act"        => "user_create",
    "user_email" => "newuser@example.com",
    "user_zone"  => "example.com"
  ),
  "result" => "success",
  "msg"    => "A message that will be displayed to the end user"
  ...
);

{}すべてを toarray()および every :toに変更するだけ=>で、PHP 構文で同じことが得られます。

于 2012-10-23T09:25:07.517 に答える
0
<?php
    $array[0]["request"] = array(
         "act"        => 'user_create', 
         "user_email" => "newuser@example.com", 
         "user_zone"  => "example.com")
    );
    $array[0]['result'] = 'success';
    $array[0]['msg'] = 'A message that will be displayed to the end user';

    ... etc. for other requests and results and msgs

    echo json_encode($array);
?>
于 2012-10-23T09:26:18.480 に答える
0

これは機能しています。JSON 形式で配列を開始するたびに、PHP で配列を作成します。

  $array = array( // "request" array
    "request" => array( // inner array
        "act"=>"user_create",
        "user_email"=>"newuser@example.com",
        "user_zone"=>"example.com"
        ),
    "result"=>"success",
    "msg"=>"A message that will be displayed to the end user"
    );
    echo json_encode($array);
于 2012-10-23T10:37:05.497 に答える