0

I want to decode a JSON string. However, the value that I got is something like this string(100) "{"data":{"type":"campaign-folders","id":"d208f3171a","attributes":{"name":"My Folder"}}}".

Could anyone tell me what should I do so that I can treat this variable as a usual string ?

1
  • “However, the value that I got is something like this” - that looks like the output var_dump creates - but in that case, it of course does not mean that this is the actual content of your string variable. string(100) is additional “meta data” var_dump provides you with (type & length.) Commented Jan 10, 2018 at 10:38

3 Answers 3

1

Use json_decode http://php.net/manual/en/function.json-decode.php

$obj = json_decode($json);
var_dump($obj);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it's work. I think I should treat the string differently, but it's just the same
0

Use json_decode ,you can solve it.

var_dump(json_decode($json, true));//check this.

Comments

0

here to convert JSON string to Array

 $someArray = json_decode($someJSON, true);
  print_r($someArray);
 echo $someArray[0]["name"];

and here to convert JSON to Object

$someObject = json_decode($someJSON);
 print_r($someObject);
 echo $someObject[0]->name;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.