开发者

How to parse JSONP with PHP [duplicate]

开发者 https://www.devze.com 2023-03-25 04:15 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Extract JSONP Resultset in PHP
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Extract JSONP Resultset in PHP

I get the response in the following format. Im facing trouble on开发者_Python百科 how to get inside "Plugin" variable and access other variables inside it.I used json_decode(), but i cant access the variables.

Plugin
(
{ 

"plugin_a":"abc", 
"plugin_b":"abc", 
"plugin_c":"abc" 
}
)

I tried

$a = json_decode($json,true);
echo  $a['plugin_a'];

I dont get any output.

echo var_dump($json); gives me

string 'Plugin({
  "plugin_a":"abc",
  "plugin_b":"abc",
  "plugin_ce":"abc" })'


try substr();

http://sandbox.phpcode.eu/g/40c20.php

<?php
$json = substr('Plugin
(
{ 

"plugin_a":"abc", 
"plugin_b":"abc", 
"plugin_c":"abc" 
}
)', 9, -1);

print_r(json_decode($json));


Perhaps this will work for you:

$data=array('plugin_a'=>'abc','plugin_b'=>'bcd','plugin_c'=>'cde');
$json='{"Plugin":'.json_encode($data).'}';
$a=json_decode($json,true);
echo $a['Plugin']['plugin_a'];

It appears as though the actual json array may not have integrity. If this solution doesn't fit, can you post the code that actually builds the json array?

0

精彩评论

暂无评论...
验证码 换一张
取 消