[ create a new paste ] login | about

Link: http://codepad.org/M4EdiGS2    [ raw code | output | fork ]

PHP, pasted on Apr 5:
1
2
3
4
5
6
7
8
<?php
$s = "[{\"roll_no\":\"1101\",\"full_name\":\"John Smith\",\"dayspresent\":\"1\",\"totalclasses\":\"2\",\"percent_att\":\"\n\t\t\t50\t\t\t\",\"hasAttended\":\"P\",\"att_date\":\"Fri Apr 05 2013 \",\"st_class\":\"1\",\"st_section\":\"A\"},{\"roll_no\":\"1102\",\"full_name\":\"Ram Puri\",\"dayspresent\":\"4\",\"totalclasses\":\"4\",\"percent_att\":\"\n\t\t\t100\t\t\t\",\"hasAttended\":\"A\",\"att_date\":\"Fri Apr 05 2013 \",\"st_class\":\"1\",\"st_section\":\"A\"}]";
$json = str_replace(array("\t","\n"), "", $s);
$a = json_decode($json, true);
foreach($a as $item)
{
    var_dump($item);
}


Output:
array(9) {
  ["roll_no"]=>
  string(4) "1101"
  ["full_name"]=>
  string(10) "John Smith"
  ["dayspresent"]=>
  string(1) "1"
  ["totalclasses"]=>
  string(1) "2"
  ["percent_att"]=>
  string(2) "50"
  ["hasAttended"]=>
  string(1) "P"
  ["att_date"]=>
  string(16) "Fri Apr 05 2013 "
  ["st_class"]=>
  string(1) "1"
  ["st_section"]=>
  string(1) "A"
}
array(9) {
  ["roll_no"]=>
  string(4) "1102"
  ["full_name"]=>
  string(8) "Ram Puri"
  ["dayspresent"]=>
  string(1) "4"
  ["totalclasses"]=>
  string(1) "4"
  ["percent_att"]=>
  string(3) "100"
  ["hasAttended"]=>
  string(1) "A"
  ["att_date"]=>
  string(16) "Fri Apr 05 2013 "
  ["st_class"]=>
  string(1) "1"
  ["st_section"]=>
  string(1) "A"
}


Create a new paste based on this one


Comments: