user4025957
user4025957

Reputation:

Read content inside json file php

I have a webservice that return me this JSON file:

{"success":true,"msg":"[{\"inCarico\":\"1\",\"a\":\"2007-01-12 00:00:00\",\"b\":\"\",\"cd\":\"\",\"ef\":\"\",\"IdL\":\"0\",\"IdM\":\"0\"}]"}

Now I am using this code to decode json and get the msg content, but I want to decode every voice (carico, a, b, IdL...) in the "msg" voice.

$url = 'http://......';
$obj = json_decode(file_get_contents($url), true);
echo $obj['msg'];

How can I do this?

Upvotes: 1

Views: 70

Answers (1)

user6364857
user6364857

Reputation:

You have to use json decode two time.

$json = '{"success":true,"msg":"[{\\"inCarico\\":\\"1\\",\\"a\\":\\"2007-01-12 00:00:00\\",\\"b\\":\\"\\",\\"cd\\":\\"\\",\\"ef\\":\\"\\",\\"IdL\\":\\"0\\",\\"IdM\\":\\"0\\"}]"}';
$result = json_decode ($json, true);

$arr = json_decode ($result['msg'], true);
print_r($arr);

Result:

Array
(
    [0] => Array
        (
            [inCarico] => 1
            [a] => 2007-01-12 00:00:00
            [b] => 
            [cd] => 
            [ef] => 
            [IdL] => 0
            [IdM] => 0
        )

)

Please notify me what can i do for you now?

Upvotes: 1

Related Questions