0

我是一个新手 php 家伙。所以我的 ios 应用程序需要 json 数据。我可以从我的数据库中获取数据并打印为 json..我想用 json 发送许多类型的数据。所以我需要编辑我的 json 输出。因此,我现在拥有的 json 输出:

[{"PlaceId":"1","PlaceAdminId":"5","PlaceName":"Alinin Yeri","PlaceAddress":"Be?ikta?","PlaceImage1":"iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAHGlET1QAAAACAAAAAAAAACgAAAAoAAAAKAAAACgAAADWVJb57gAAAKJJREFUeAHs1LEJADAMA8Hsv3SyQ6RGcIVLG\/FYf+69x\/wzAC98IAAB\/K9fQ10+0Af6wOkWTIdvOCy9ASAHcuB0C6bDp\/5q7APIgRw43YLp8A2HpTcA5EAOnG7BdPjUX419ADmQA6dbMB2+4bD0BoAcyIHTLZgOn\/qrsQ8gB3LgdAumwzcclt4AkAM5cLoF0+FTfzX2AeRADpxuwXT4hsPSGw8AAP\/\/ttPzCAAAAKBJREFU7dSxCQAwDAPB7L90skOkRnCFSxvxWH\/uvcf8MwAvfCAAAfyvX0NdPtAH+sDpFkyHbzgsvQEgB3LgdAumw6f+auwDyIEcON2C6fANh6U3AORADpxuwXT41F+NfQA5kAOnWzAdvuGw9AaAHMiB0y2YDp\/6q7EPIAdy4HQLpsM3HJbeAJADOXC6BdPhU3819gHkQA6cbsF0+IbD0hsPozm5V7YwxV0AAAAASUVORK5CYII=","PlaceImage2":null,"PlaceImage3":null,"PlaceImage4":null},

{"ActivityId":"1","ActivityName":"zulfu livaneli","ActivityDescription":"Zulfu konseri","ActivityType":"1","ActivityDate":"2011-00-00","PlaceName":"Alinin Yeri","PlaceId":"1"},

{"ActivityId":"2","ActivityName":"Bir tat bir doku","ActivityDescription":"Y?lmaz Erdo?an oyunu","ActivityType":"3","ActivityDate":"2013-00-00","PlaceName":"Alinin Yeri","PlaceId":"1"},

这就是我想要的:

[Places:{{"PlaceId":"1","PlaceAdminId":"5","PlaceName":"Alinin Yeri","PlaceAddress":"Be?ikta?","PlaceImage1":"iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAHGlET1QAAAACAAAAAAAAACgAAAAoAAAAKAAAACgAAADWVJb57gAAAKJJREFUeAHs1LEJADAMA8Hsv3SyQ6RGcIVLG\/FYf+69x\/wzAC98IAAB\/K9fQ10+0Af6wOkWTIdvOCy9ASAHcuB0C6bDp\/5q7APIgRw43YLp8A2HpTcA5EAOnG7BdPjUX419ADmQA6dbMB2+4bD0BoAcyIHTLZgOn\/qrsQ8gB3LgdAumwzcclt4AkAM5cLoF0+FTfzX2AeRADpxuwXT4hsPSGw8AAP\/\/ttPzCAAAAKBJREFU7dSxCQAwDAPB7L90skOkRnCFSxvxWH\/uvcf8MwAvfCAAAfyvX0NdPtAH+sDpFkyHbzgsvQEgB3LgdAumw6f+auwDyIEcON2C6fANh6U3AORADpxuwXT41F+NfQA5kAOnWzAdvuGw9AaAHMiB0y2YDp\/6q7EPIAdy4HQLpsM3HJbeAJADOXC6BdPhU3819gHkQA6cbsF0+IbD0hsPozm5V7YwxV0AAAAASUVORK5CYII=","PlaceImage2":null,"PlaceImage3":null,"PlaceImage4":null}},

Activities:{{"ActivityId":"1","ActivityName":"zulfu livaneli","ActivityDescription":"Zulfu konseri","ActivityType":"1","ActivityDate":"2011-00-00","PlaceName":"Alinin Yeri","PlaceId":"1"},

{"ActivityId":"2","ActivityName":"Bir tat bir doku","ActivityDescription":"Y?lmaz Erdo?an oyunu","ActivityType":"3","ActivityDate":"2013-00-00","PlaceName":"Alinin Yeri","PlaceId":"1"},

{"ActivityId":"3","ActivityName":null,"ActivityDescription":"Y?l?n son derbisi","ActivityType":"2","ActivityDate":"2012-00-00","PlaceName":"Alinin Yeri","PlaceId":"1"}}] 

和我的php代码:

$showresult = mysql_query($sqlQuery1);
$showresult1 = mysql_query($sqlQuery2);
$multi_array = array();
$multi_array1 = array();
while($row = mysql_fetch_assoc($showresult)){
  $multi_array[] = $row;
}
while($row = mysql_fetch_assoc($showresult1)){
 $multi_array1[] = $row;
}
$result = array_merge($multi_array1, $multi_array);
print json_encode($result);

编辑或者有什么方法可以做我想做的事吗?

4

1 回答 1

2

将您的代码分成两部分。一部分从数据库中获取“Places”行,第二部分从数据库中获取“Activties”行。然后你做类似的事情

$php_result=array(
"Places"=> $places_rows,
"Activities"=> $activities_rows 
);

$json_result= json_encode($php_result);
于 2013-09-05T15:22:13.983 回答