1

I have a JSONArray as

{"test":
[
{"Name":"aaa","Reg/Admission Number":"001"},
{...}]}

And I can separate Name by

$read_data = array();
foreach ($data->test as $result){
  $name = $result->Name;
  $read_data[] = "('$name')";
}

the result of read_data as ('aaa'),('bbb')...

Anyone can suggest how to separate the array of Reg/Admission Number which has the special character as '/' and 'space'

3
  • inside the for each add this var_dump($result); and look the name of that field. Commented Jan 13, 2015 at 4:50
  • 1
    have you tried using an escape character? like Reg\/Admission\ Number? alternatively i believe $result->{'Reg/Admission Number'} should work Commented Jan 13, 2015 at 4:51
  • @haxxxton $result->{'Reg/Admission Number'}` it works fine.. thanks for your suggestion Commented Jan 13, 2015 at 4:54

3 Answers 3

4

Why Dont you use the php function

  1. json_encode() http://php.net/manual/en/function.json-encode.php

  2. json_decode() http://php.net/manual/en/function.json-decode.php

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

Comments

1

As per @haxxxton suggestion it works

 $read_data = array();
    foreach ($data->test as $result){
      $name = $result->Name;
      $no = $result->{'Reg/Admission Number'}`
      $read_data[] = "('$name','$no')";
    }

Comments

0

You can convert json array to PHP array first and then can do your operation.

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.