PHP中的特定JSON格式 - php

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center获取指导。

7年前关闭。

我需要带有php代码的json格式

有没有办法生成这样的JSON
用PHP?

[
      {
         "name":"Steve",
         "company":"Apple"
      },
      {
         "name":"Bill",
         "company":"Microsoft"
      }
]

有人可以帮忙吗?

参考方案

您要这样做吗?

$a = array();
$b = array('name' => '', 'company' => '');

$b['name'] = 'Steve';
$b['company'] = 'Apple';
$a[]= $b;

$b['name'] ='Bill';
$b['company']='Microsoft';
$a[]= $b;

echo json_encode($a);

这会给你

[
  {
    "name": "Steve",
    "company": "Apple"
  },
  {
    "name": "Bill",
    "company": "Microsoft"
  }
]

PHP:将数组值加在一起 - php

我相信这比标题听起来要难一些,但我可能完全错了。我有一个像这样的数组:[["londrina",15],["cascavel",34],["londrina",23],['tiradentes',34],['tiradentes',21]] 我希望能够采用通用…

PHP JQuery复选框 - php

我有以下片段。 var myData = { video: $("input[name='video[]']:checked").serialize(), sinopse: $("#sinopse").val(), dia: $("#dia").val(), quem: $(&#…

PHP-MySQL结果转换为JSON - php

我试图了解如何将MySQL结果转换为JSON格式,以便以后可以在Javascript中使用此JSON来构建HTML表。但是我的代码只是产生大量的空值,我还不明白为什么。$result = mysqli_query($con, "SELECT * FROM Customers"); $test = json_encode($result);…

json_encode网址失败 - php

有人在this bug附近吗?echo json_encode(array('url'=>'/foo/bar')); {"url":"\/foo\/bar"} 我使用Zend_Json and Zend_Json_Expr以便我甚至可以在js对象中获取回调函数-但我无法获得…

json_encode的特定方式 - php

所以这是我的PHP<?php include 'connect.php'; $sql = "SELECT name from startup_schema"; $result = mysqli_query($mysqli, $sql) or die("Error in Selecting " …