我是一个新手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);
EDIT 或者有什么方法可以做我想要的吗?
答案 0 :(得分:2)
将代码分为两部分。一部分从数据库中获取“Places”行,第二部分从数据库中获取“Activties”行。然后你做一些像
这样的事情$php_result=array(
"Places"=> $places_rows,
"Activities"=> $activities_rows
);
$json_result= json_encode($php_result);