Converting a php array to a unicode json -
i need convert dynamic array following format. posting sample
{u'v2':{0:u'no',1:u'yes'}, u'v3':{1:u'maybe',3:u'almost'}} this did:
$vallabels = array(); $vallabeltemp1 = array(); $vallabeltemp2 = array(); $vallabeltemp1['v2'][0] = 'no'; $vallabeltemp1['v2'][1] = 'yes'; $vallabels = $vallabeltemp1; $vallabeltemp2['v3'][0] = 'maybe'; $vallabeltemp2['v3'][1] = 'almost'; $vallabels = $vallabeltemp2; when write above in text file:
fwrite($fh,json_encode($vallabels) . "\n");
i following output:
{"v2":["no","yes"],"v3":["maybe","almost"]} i dun want above format. plus need affix 'u' represent unicode. not sure how can format. advance thanks.
you can this:
<?php $vallabels = array( 'v2' => array('1' => 'yes', '0' => 'no'), 'v3' => array('1' => 'maybe','3' => 'almost') ); echo json_encode($vallabels); output:
{"v2":{"1":"yes","0":"no"},"v3":{"1":"maybe","3":"almost"}} nb: need revert (this doesn't matter in json result) v2 data otherwise php kind of smart type convertion , loose indices.
Comments
Post a Comment