0

I have the following json output - I've tried multiple things however not having any luck - I just want to get the value for kind (software-package). Any ideas:

{"items":
[{"assets":
[{"kind":"software-package","url":"__URL__"}],
"metadata":{"bundle-identifier":"SimpleCalculator",
"bundle-version":"000","kind":"software",
"title":"com.work.demo","subtitle":"1.0"}

Thanks,

1
  • If it is typo, you could use json_decode, otherwise take it as string and use preg_match and regex Commented Sep 19, 2013 at 11:33

3 Answers 3

2

Try to decode it with json_encode like

$result_arr = json_decode($my_arr,true);
print_r($result_arr['items']['assets']['kind']);
Sign up to request clarification or add additional context in comments.

2 Comments

missed true as second argument. And the path seems not correct
items and assets are array. so $result['items'][0]['assets'][0]
0

That is not valid JSON.

Lets attempts to format that a little more sensibly.

{"items": [
    {"assets": [
        {"kind":"software-package","url":"__URL__"}
     ],
     "metadata":{"bundle-identifier":"SimpleCalculator",
                 "bundle-version":"000","kind":"software",
                 "title":"com.work.demo","subtitle":"1.0"
                }

You're missing a lot of closing brackets. :(

How are you acquiring this JSON. Is it hand formatted or generated by some software? They're may be bugs in the source, and not your code.

Comments

0

If you are using a version of PHP above 5.3 then there are built-in functions to decode and encode JSON strings already.

$some_json_string = {......};
$json_string_as_object = json_decode($some_json_string);
$json_string_as_array = json_decode($some_json_string, true);

You can also do the reverse:

$some_array = array(...);
$json_string = json_encode($some_array);

Json Decode : http://php.net/manual/en/function.json-decode.php Json Encode: http://www.php.net/manual/en/function.json-encode.php

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.