-4

I'm useing PHP. my string is:

[{"name":"emailaddress","value":"me@you.com"},
{"name":"familyname","value":"kasjhdf"},{"name":"mothersname","value":"kjh"},
{"name":"motherscellphone","value":"23423423423"},
{"name":"fathersname","value":""},{"name":"fatherscellphone","value":""},
{"name":"childdates1.datesAttending","value":"24"},
{"name":"childdates1.datesAttending","value":"26"},
{"name":"childdates1.datesAttending","value":"25"},
{"name":"childname1.child_name","value":"asd"},
{"name":"childdob1.child_dob","value":"09/08/2015"},
{"name":"childallergies1.child_allergies","value":"asdf"},
{"name":"childinstructions1.child_instructions","value":"a"},
{"name":"childbelongings1.belongings","value":"sawef"},
{"name":"datesAttending","value":""},{"name":"child_name","value":""},
{"name":"child_dob","value":""},{"name":"child_allergies","value":""},
{"name":"child_instructions","value":""},{"name":"belongings","value":""},
{"name":"groupid","value":"zzzz"},{"name":"job_date_id_count","value":"3"},
{"name":"child_count","value":"1"},{"name":"job_group_name_id","value":"83"},
{"name":"job_group_email_id","value":"55"},{"name":"willbill","value":"0"},
{"name":"form_submitted","value":"1"}]

I also need to combine the like values like this:

{"name":"childdates1.datesAttending","value":"24"},
{"name":"childdates1.datesAttending","value":"26"},
{"name":"childdates1.datesAttending","value":"25"}, 

so the array field would be Array ([childdates[0].datesAttending] => 24,26,25 )

And my Array would be:

 Array ( [emailaddress] => me@you.com [familyname] => skadjhf [mothersname] 
=> kjh [motherscellphone] => 234234234343 [fathersname] => [fatherscellphone] => 
234234234324 [child[0] => [0.child_name] => lkjasdf [child[1] => [1.child_name] 
=> sdfwef [child_name] => [child_dob] => [child_allergies] => 
[child_instructions] => [belongings] => [groupid] => zzzz [job_date_id_count] => 
2 [child_count] => 1 [job_group_name_id] => 83 [job_group_email_id] => 55 
[willbill] => 0 [form_submitted] => 1 )

4 Answers4

1

If you have the JSON in a string variable like,

$my_json_string = '[{"name":"emailaddress","value":"me@you.com"}...';

Then use: json_decode()

$my_json_array = json_decode($my_json_string );

tmarois
  • 2,424
  • 2
  • 31
  • 43
0

Have a look at: http://php.net/manual/en/ref.json.php

All the json functions are found there and described quite simple.

and

How to convert JSON string to array

Once you have the arrays you can look into:

There are quite a lot of answers on here that explain just that.

Community
  • 1
  • 1
Drmzindec
  • 804
  • 2
  • 15
  • 28
0
$json = '{"name":"abc","age":"20","lastname":"xyz"}';

print_r(json_decode($json));

use json_decode() function to convert in into array.

Shailesh Katarmal
  • 2,757
  • 1
  • 12
  • 15
0

You can also use code like this to convert your json into array

$myArray = json_decode($decodedText, true);

Ashish Shukla
  • 1,027
  • 16
  • 36