使用php

时间:2018-08-14 16:45:06

标签: php arrays json

我想在数组之前添加 Data 并将其写入转换后的json中。 我检查了转换时没有错误,但是为什么不存在?

此代码

$response = array();
while($row =mysqli_fetch_assoc($result))
{
    $response[] = $row;
}
echo json_encode($response);
    //write to json file
$fp = fopen('op.json', 'w');
fwrite($fp, json_encode('{"Data":', $response), '}');// JSON_PRETTY_PRINT
fclose($fp);

以前的结果

[
  {
    "id": "6",
    "name": "kiko",
    "score": "999"
  },
  {
    "id": "9",
    "name": "johyn",
    "score": "88"
  },
  {
    "id": "12",
    "name": "aaaani",
    "score": "99"
  }
]

我想要这样的结果

{
  "Data": [
    {
      "id": "6",
      "name": "kiko",
      "score": "999"
    },
    {
      "id": "9",
      "name": "johyn",
      "score": "88"
    },
    {
      "id": "12",
      "name": "aaaani",
      "score": "99"
    }
  ]
}

2 个答案:

答案 0 :(得分:2)

json_encode()将数组或对象编码为JSON字符串,因此将参数设置为数组即可使用

json_encode()

或者获取JSON_PRETTY_PRINT

fwrite($fp, json_encode(["Data" => $response]);

答案 1 :(得分:1)

您可以使用数组来生成所需的输出,而不是先对JSON进行编码,然后Severity Code Description Project File Line Suppression State Error TS2339 (TS) Property 'length' does not exist on type '{}'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\pollution\pollution.component.ts 101 Active Error TS2415 (TS) Class 'FocusKeyManager<T>' incorrectly extends base class 'ListKeyManager<FocusableOption & T>'. Types of property 'setActiveItem' are incompatible. Type '(index: number) => void' is not assignable to type '{ (index: number): void; (item: FocusableOption & T): void; }'. Types of parameters 'index' and 'item' are incompatible. Type 'FocusableOption & T' is not assignable to type 'number'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\a11y\typings\key-manager\focus-key-manager.d.ts 19 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\collections\typings\data-source.d.ts 8 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\collections\typings\selection.d.ts 8 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\layout\typings\breakpoints-observer.d.ts 10 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\overlay\typings\overlay-ref.d.ts 11 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\overlay\typings\overlay-ref.d.ts 12 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\overlay\typings\position\connected-position-strategy.d.ts 12 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subscription"' has no exported member 'Subscription'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\scrolling\typings\scroll-dispatcher.d.ts 10 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\scrolling\typings\scroll-dispatcher.d.ts 11 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\scrolling\typings\scrollable.d.ts 9 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\scrolling\typings\viewport-ruler.d.ts 10 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\cdk\stepper\typings\stepper.d.ts 12 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\compiler\src\output\output_ast.d.ts 600 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\compiler\src\output\output_ast.d.ts 601 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\compiler\src\output\output_ast.d.ts 602 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\container.d.ts 35 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\container.d.ts 40 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\container.d.ts 45 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\container.d.ts 50 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\container.d.ts 58 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\container.d.ts 79 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 50 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 56 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 66 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 68 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 70 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 79 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 87 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 94 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 103 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 109 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 111 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 113 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 115 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 122 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 131 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\render3\interfaces\view.d.ts 137 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 10 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 11 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 12 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 13 Active Error TS2474 (TS) In 'const' enum declarations member initializer must be constant expression. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 14 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 23 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 31 Active Error TS2535 (TS) Enum type 'BypassType' has members with initializers that are not literals. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 31 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 39 Active Error TS2535 (TS) Enum type 'BypassType' has members with initializers that are not literals. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 39 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 47 Active Error TS2535 (TS) Enum type 'BypassType' has members with initializers that are not literals. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 47 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 55 Active Error TS2535 (TS) Enum type 'BypassType' has members with initializers that are not literals. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 55 Active Error TS1169 (TS) A computed property name in an interface must directly refer to a built-in symbol. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 63 Active Error TS2535 (TS) Enum type 'BypassType' has members with initializers that are not literals. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\core\src\sanitization\bypass.d.ts 63 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\autocomplete\typings\autocomplete-trigger.d.ts 14 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\chips\typings\chip-list.d.ts 15 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\chips\typings\chip.d.ts 11 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\core\typings\common-behaviors\error-state.d.ts 11 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\core\typings\common-behaviors\initialized.d.ts 9 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\core\typings\datetime\date-adapter.d.ts 9 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\core\typings\datetime\date-adapter.d.ts 10 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\core\typings\option\option.d.ts 1 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\datepicker\typings\datepicker-intl.d.ts 1 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\dialog\typings\dialog-ref.d.ts 11 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\dialog\typings\dialog.d.ts 5 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\dialog\typings\dialog.d.ts 6 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\expansion\typings\expansion-panel.d.ts 13 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\form-field\typings\form-field-control.d.ts 8 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Observable"' has no exported member 'Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\icon\typings\icon-registry.d.ts 4 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\sort\typings\sort-header-intl.d.ts 9 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\sort\typings\sort.d.ts 11 Active Error TS2305 (TS) Module '"C:/Users/anon/Documents/Projects/EEA.Projects/DEP/MassAir/Web/node_modules/rxjs/Subject"' has no exported member 'Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\@angular\material\stepper\typings\stepper-intl.d.ts 1 Active Error TS2307 (TS) Cannot find module 'rxjs-compat/Observable'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\rxjs\Observable.d.ts 1 Active Error TS2307 (TS) Cannot find module 'rxjs-compat/Subject'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\rxjs\Subject.d.ts 1 Active Error TS2307 (TS) Cannot find module 'rxjs-compat/Subscription'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\node_modules\rxjs\Subscription.d.ts 1 Active Error TS2345 (TS) Argument of type '{}' is not assignable to parameter of type 'string'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\lookup\lookup.component.ts 68 Active Error TS2345 (TS) Argument of type '{}' is not assignable to parameter of type 'string'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\monitor\monitor.component.ts 76 Active Error TS2345 (TS) Argument of type '{}' is not assignable to parameter of type 'string'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\parameter\parameter.component.ts 76 Active Error TS2339 (TS) Property 'length' does not exist on type '{}'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\pollution\pollution.component.ts 110 Active Error TS2345 (TS) Argument of type '{ }' is not assignable to parameter of type 'string'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\rule\rule.component.ts 89 Active Error TS2345 (TS) Argument of type '{}' is not assignable to parameter of type 'string'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\rule\rule.component.ts 99 Active Error TS2345 (TS) Argument of type '{}' is not assignable to parameter of type 'string'. C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web (tsconfig or jsconfig project) C:\Users\anon\Documents\Projects\EEA.Projects\DEP\MassAir\Web\src\app\components\site\site.component.ts 125 Active

json_encode()

此外,$response = array(); while($row =mysqli_fetch_assoc($result)) { $response[] = $row; } echo json_encode($response); //write to json file $fp = fopen('op.json', 'w'); fwrite($fp, json_encode(array('Data' => $response), JSON_PRETTY_PRINT)); // JSON_PRETTY_PRINT fclose($fp); 可以通过提供第二个参数来精美打印 json。