1<?php
2$data = ['name' => 'John', 'age' => 35];
3header('Content-type: Application/json');
4echo json_encode($data);
5
1using Newtonsoft.Json;
2using Newtonsoft.Json.Converters;
3
4[JsonConverter(typeof(StringEnumConverter))]
5public Gender Gender { get; set; }
1$person = array(
2 "name" => "Johny Carson",
3 "title" => "CTO"
4);
5$personJSON=json_encode($person);//returns JSON string
1
2 <?php
3$age = {"numberPlate":"CPV453","documentType":null,"documentNumber":"12962552","email":"xxx@xxx.com","phone":"","entityId":"45500","contactId":"7825235","respCaptcha":"","runtVehicleConfiguration":null}
4
5
6echo json_encode($age);
7?>
8
1struct GroceryProduct: Codable {
2 var name: String
3 var points: Int
4 var description: String?
5}
6
7let json = """
8{
9 "name": "Durian",
10 "points": 600,
11 "description": "A fruit with a distinctive scent."
12}
13""".data(using: .utf8)!
14
15let decoder = JSONDecoder()
16let product = try decoder.decode(GroceryProduct.self, from: json)
17
18print(product.name) // Prints "Durian"
19
1
2 <?php
3$age = array("Peter"=>35, "Ben"=>37, "Joe"=>43);
4
5
6echo json_encode($age);
7?>
8