0

In my php file im using the following,

$obj = ($_POST['data']);
var_dump(json_decode($obj,true));

And i see this result. Is this the correct format? and how do i access the array.

eg, set a new variable $newID the same as row1 id

array(4) {
  ["row0"]=>
  string(92) "{"id":"157","name":"123","basic":"123123123","submitter":"Keith","status":"review"}"
  ["row1"]=>
  string(169) "{"id":"158","name":"TEST RESOURCE","basic":"Please state the type of work.","submitter":"Keith","status":"review"}"
  ["row2"]=>
  string(107) "{"id":"159","name":"TEST OTHER","basic":"testing for other","submitter":"Keith","status":"review"}"
  ["row3"]=>
  string(160) "{"id":"160","name":"Name","basic":"type of work","submitter":"Keith","status":"review"}"
}

heres whats in POST in firebug

data    {"row0":"{\"id\":\"157\",\"name\":\"123\",\"basic\":\"123123123\",\"submitter\":\"Keith\",\"status\":\"review\"}","row1":"{\"id\":\"158\",\"name\":\"TEST RESOURCE\",\"basic\":\"Please state the type of work.\",\"submitter\":\"Keith\",\"status\":\"review\"}","row2":"{\"id\":\"159\",\"name\":\"TEST OTHER\",\"basic\":\"testing for other\",\"submitter\":\"Keith\",\"status\":\"review\"}","row3":"{\"id\":\"160\",\"name\":\"Name\",\"basic\":\"type of work\",\"submitter\":\"Keith\",\"status\":\"review\"}"} 
2
  • 1
    Can you post the original JSON-string you are getting? Commented Feb 6, 2013 at 10:31
  • updated with what post data i have Commented Feb 6, 2013 at 10:41

1 Answer 1

1

Each "row" of the array is another JSON string. It seems like the data was double-encoded, like:

$array = json_encode(
    array(
        'row0' => json_encode(array('id' => '157', ...)),
        ...
    )
)

This is incorrectly encoded data, unless you wanted JSON objects inside JSON objects. To work with it, you need to json_decode each individual item again. Better though: fix the encoding step.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes each json object is another jsonobject. Try something like : $result = array(); $var = json_decode($obj,true); foreach ($var as $k=>$v) $result[$k]=json_decode($v,true);

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.