0

I have a Json as follows in which I 've to get only transId inside response in php. please help as I am new to php

{
    "type": null,
    "requestuid": null,
    "orderId": "anand12345",
    "status": "SUCCESS",
    "statusCode": "SUCCESS",
    "statusMessage": "SUCCESS",
    "response": {
        "transId": "1408544"
    },
    "metadata": "Testing Data"
}
4
  • you want to extract transId. is that what you mean? Commented Nov 30, 2018 at 10:29
  • Yes, I exactly want to get transId Commented Nov 30, 2018 at 10:30
  • 1
    You might need to look at this function php.net/manual/fr/function.json-decode.php . Not that a boolean can be passed as second argument to force the conversion to produce an associative array or a StdClass Commented Nov 30, 2018 at 10:31
  • 1
    Suggestion: Before posting, make sure you have done proper research. It would have been pretty easy to find this information since it's been asked and answered many many times. Commented Nov 30, 2018 at 10:32

2 Answers 2

3
$json = '{
 "type": null,
 "requestuid": null,
 "orderId": "anand12345",
 "status": "SUCCESS",
 "statusCode": "SUCCESS",
 "statusMessage": "SUCCESS",
 "response": {"transId": "1408544"},
 "metadata": "Testing Data"
}';

$arr = json_decode($json,true);
$transId = $arr['response']['transId'];
Sign up to request clarification or add additional context in comments.

Comments

1

read your file and store its content as a string (here i directly declared a string stored in $json ) using json_decode php function you get an object with all your data and just have to use field names to access your data

$json = '{
"type": null,
"requestuid": null,
"orderId": "anand12345",
"status": "SUCCESS",
"statusCode": "SUCCESS",
"statusMessage": "SUCCESS",
"response": {
    "transId": "1408544"
},
"metadata": "Testing Data"

}';


$decoded = json_decode($json);
echo $decoded->response->transId;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.