Answers for "convert json to array php online"

PHP
3

convert json to array in php

<?php
  // JSON string
  $someJSON = '[{"name":"Jonathan Suh","gender":"male"},{"name":"William Philbin","gender":"male"},{"name":"Allison McKinnery","gender":"female"}]';

  // Convert JSON string to Array
  $someArray = json_decode($someJSON, true);
  print_r($someArray);        // Dump all data of the Array
  echo $someArray[0]["name"]; // Access Array data

  // Convert JSON string to Object
  $someObject = json_decode($someJSON);
  print_r($someObject);      // Dump all data of the Object
  echo $someObject[0]->name; // Access Object data
?>
Posted by: Guest on June-26-2020
0

json to array php

//2 ways
  //this is for string from $_REQUEST,$_POST to array
$jsonText = $_REQUEST['myJSON'];
$decodedText = html_entity_decode($jsonText);
$myArray = json_decode($decodedText, true);

//this is for json to array
$assosiative_array = json_decode(json_encode($jsonText),true);
Posted by: Guest on July-26-2021
1

json to array php

<?php

$myArr = '{
  "neworder": {
    "-newfolder": "NO",
    "auth": {
      "-extra": "8",
      "-login": "login",
      "-pass": "pass"
    },
    "order": {
      "-orderno": "111111",
      "barcode": "111111",
      "sender": {
        "company": "Ministry of Internal Affairs",
        "person": "I. I. Ivanov",
        "phone": "123-45-67",
        "town": "Saint-Petersburg",
        "address": "Petrovka Str., 38, room 35",
        "date": "2021-03-22",
        "time_min": "09:00",
        "time_max": "14:00"
      },
      "receiver": {
        "company": "Ministry of Internal Affairs",
        "person": "Tom Wale",
        "phone": "123-45-67",
        "zipcode": "125480",
        "town": {
          "-regioncode": "78",
          "-country": "RU",
          "#text": "Saint-Petersburg"
        },
        "address": "Petrovka Str., 38, room 35",
        "pvz": "124",
        "inn": "1112223335",
        "date": "2021-03-22",
        "time_min": "09:00",
        "time_max": "14:00",
        "deliveryPIN": "1234",
        "coords": {
          "-lat": "55.680327",
          "-lon": "37.604456"
        }
      },
      "return": "NO",
      "weight": "5.1",
      "return_weight": "5.1",
      "quantity": "2",
      "paytype": "CASH",
      "service": "2",
      "return_service": "1",
      "type": "3",
      "return_type": "3",
      "courier": "22",
      "price": "387.5",
      "deliveryprice": {
        "-VATrate": "20",
        "#text": "150"
      },
      "inshprice": "387.5",
      "receiverpays": "NO",
      "discount": "120",
      "enclosure": "Kids toys",
      "instruction": "Check in the presence of the buyer, sign acceptance certificate",
      "department": "Accounting",
      "pickup": "NO",
      "acceptpartially": "NO",
      "costcode": "cc12345",
      "items": {
        "item": [
          {
            "-extcode": "abc123",
            "-quantity": "1",
            "-mass": "0.2",
            "-retprice": "37.5",
            "-VATrate": "0",
            "-barcode": "2345625213125",
            "-textArticle": "1",
            "-article": "1",
            "-volume": "3",
            "-origincountry": "AUT",
            "-GTD": "321546654",
            "-excise": "15.20",
            "-suppcompany": "LLC \"Miller and Partners\"",
            "-suppphone": "79161234567",
            "-suppINN": "1112223334",
            "-governmentCode": "11223311",
            "#text": "Race car"
          },
          {
            "-extcode": "abc124",
            "-quantity": "2",
            "-mass": "2",
            "-retprice": "100",
            "-inshprice": "100",
            "-VATrate": "10",
            "-barcode": "4645625213138",
            "-article": "2",
            "-length": "10",
            "-width": "20",
            "-height": "30",
            "-origincountry": "004",
            "#text": "Princess castle"
          },
          {
            "-extcode": "abc125",
            "-quantity": "3",
            "-mass": "0.3",
            "-retprice": "50",
            "-inshprice": "50",
            "-barcode": "2345625213126",
            "-itemcode": "44123",
            "-article": "3",
            "-type": "1",
            "#text": "Clay mass"
          }
        ]
      },
      "packages": {
        "package": [
          {
            "-strbarcode": "ORD0000001",
            "-mass": "1",
            "-message": ""
          },
          {
            "-strbarcode": "ORD0000002",
            "-mass": "2.5",
            "-message": "",
            "-length": "10",
            "-width": "20",
            "-height": "30"
          }
        ]
      },
      "deliveryset": {
        "-above_price": "100",
        "-return_price": "1000",
        "-VATrate": "10",
        "below": [
          {
            "-below_sum": "500",
            "-price": "500",
            "-self-closing": "true"
          },
          {
            "-below_sum": "2000",
            "-price": "300",
            "-self-closing": "true"
          }
        ]
      },
     
      "overall_volume": "81",
      "userid": "123",
      "groupid": "456"
    }
  }
}';
    print_r(json_decode($myArr)); ?>
Posted by: Guest on September-15-2021
0

convert json to array in php

<?php
  // Loop through Array
  $someArray = ...; // Replace ... with your PHP Array
  foreach ($someArray as $key => $value) {
    echo $value["name"] . ", " . $value["gender"] . "<br>";
  }

  // Loop through Object
  $someObject = ...; // Replace ... with your PHP Object
  foreach($someObject as $key => $value) {
    echo $value->name . ", " . $value->gender . "<br>";
  }
?>
Posted by: Guest on June-08-2021

Code answers related to "convert json to array php online"

Browse Popular Code Answers by Language