अपने Android ऐप में, आप JSONArray की अपेक्षा करते हैं:
// store incoming stream in an array
JSONArray jArray = new JSONArray(streamToString(instream));
हालाँकि, आपकी PHP फ़ाइल में आप वास्तविक सरणी के बजाय केवल कई अलग-अलग JSON ऑब्जेक्ट आउटपुट करते हैं। मुझे लगता है, आपको पहले एक PHP सरणी में डेटाबेस से सभी आइटम एकत्र करना चाहिए और फिर इसे केवल एक बार एन्कोड और आउटपुट करना चाहिए।
मेरे PHP कौशल में कुछ जंग लग गया है, लेकिन मुझे आशा है कि यह काम करेगा:
//store # of rows returned
$num_rows = mysql_num_rows($query);
if ($num_rows >= 1) {
$output = array();
while($results = mysql_fetch_assoc($query)) {
// append row to output
$output[] = results
}
mysql_close(); // shouldn't that be outside the if block?
//encode the returned data in JSON format
echo json_encode($output);
}
मैं उम्मीद करता हूं कि आउटपुट इस तरह होगा (शायद इंडेंटेशन के बिना):
[
{"nid":"1","vid":"1","type":"goal","language":"","title":"test","uid":"1","status":"1","created":"1342894493","changed":"1342894493","comment":"2","promote":"1","moderate":"0","sticky":"1","tnid":"0","translate":"0"},
{"nid":"2","vid":"2","type":"goal","language":"","title":"test2","uid":"1","status":"1","created":"1342894529","changed":"1342894529","comment":"2","promote":"1","moderate":"0","sticky":"1","tnid":"0","translate":"0"},
{"nid":"5","vid":"5","type":"goal","language":"","title":"run","uid":"1","status":"1","created":"1343506987","changed":"1343506987","comment":"2","promote":"1","moderate":"0","sticky":"1","tnid":"0","translate":"0"},
{"nid":"9","vid":"9","type":"goal","language":"","title":"run to the hills","uid":"1","status":"1","created":"1343604338","changed":"1343605100","comment":"2","promote":"0","moderate":"0","sticky":"0","tnid":"0","translate":"0"}
]