-1

I got a json data in return in my php script and this json data is stored in my variable. Now i would like to check the "price" for name "express" in php. Please guide me the way to extract the data in php.

$serviceTypesJSON = json_decode($rawBody, true);

{
  "services": {
    "service": [
      {
        "code": "INT_PARCEL_COR_OWN_PACKAGING",
        "name": "Courier",
        "price": "85.13",
        "max_extra_cover": 5000,
        "options": {
          "option": [
            {
              "code": "INT_TRACKING",
              "name": "Tracking"
            },
            {
              "code": "INT_SMS_TRACK_ADVICE",
              "name": "SMS track advice"
            },
            {
              "code": "INT_EXTRA_COVER",
              "name": "Extra Cover"
            }
          ]
        }
      },
      {
        "code": "INT_PARCEL_EXP_OWN_PACKAGING",
        "name": "Express",
        "price": "40.13",
        "max_extra_cover": 5000,
        "options": {
          "option": [
            {
              "code": "INT_TRACKING",
              "name": "Tracking"
            },
            {
              "code": "INT_SIGNATURE_ON_DELIVERY",
              "name": "Signature on delivery"
            },
            {
              "code": "INT_SMS_TRACK_ADVICE",
              "name": "SMS track advice"
            },
            {
              "code": "INT_EXTRA_COVER",
              "name": "Extra Cover"
            }
          ]
        }
      },
      {
        "code": "INT_PARCEL_STD_OWN_PACKAGING",
        "name": "Standard",
        "price": "31.40",
        "max_extra_cover": 5000,
        "options": {
          "option": [
            {
              "code": "INT_TRACKING",
              "name": "Tracking"
            },
            {
              "code": "INT_EXTRA_COVER",
              "name": "Extra Cover"
            },
            {
              "code": "INT_SIGNATURE_ON_DELIVERY",
              "name": "Signature on delivery"
            },
            {
              "code": "INT_SMS_TRACK_ADVICE",
              "name": "SMS track advice"
            }
          ]
        }
      },
      {
        "code": "INT_PARCEL_AIR_OWN_PACKAGING",
        "name": "Economy Air Parcels",
        "price": "23.77",
        "max_extra_cover": 500,
        "options": {
          "option": [
            {
              "code": "INT_EXTRA_COVER",
              "name": "Extra Cover"
            },
            {
              "code": "INT_SIGNATURE_ON_DELIVERY",
              "name": "Signature on delivery"
            }
          ]
        }
      }
    ]
  }
}

Now how to extract the "name": "Express", "price": "40.13", from this variable? I would like to take the express, standard, Economy Air Parcels price. Please help me how to extract the exact data from this json mixed data

wind
  • 338
  • 2
  • 11

1 Answers1

0
var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';

var obj = JSON.parse(text);

document.getElementById("demo").innerHTML =
obj.name + "<br>" +
obj.street + "<br>" +
obj.phone;

You can use this method.

jmattheis
  • 10,494
  • 11
  • 46
  • 58
Abw
  • 1
  • 3
  • While this code snippet may solve the question, including an explanation [really helps](//meta.stackexchange.com/q/114762) to improve the quality of your post. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Nov 01 '16 at 08:48
  • Thanks for your reply. I would like to know the process in php not in javasccript. – wind Nov 01 '16 at 10:05