5

Possible Duplicate:
Extract JSONP Resultset in PHP

I get the response in the following format. Im facing trouble on 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" })'
Community
  • 1
  • 1
simplyblue
  • 2,279
  • 8
  • 41
  • 67

2 Answers2

0

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));
genesis
  • 50,477
  • 20
  • 96
  • 125
0

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?

Adam MacDonald
  • 1,958
  • 15
  • 19