Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I send valid JSON back to iOS application?
    text
    copied!<p>I have a problem. I'm trying for weeks now to fetch data from a database, encode it to JSON and then send it back to my iOS application. The problem is that every time the JSON is not valid says <a href="http://jsonviewer.stack.hu/." rel="nofollow">http://jsonviewer.stack.hu/</a> Here is the code I have now:</p> <pre><code>//connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL&lt;br&gt;"; //select a database to work with $selected = mysql_select_db("test",$dbhandle) or die("Could not select examples"); $result = mysql_query("SELECT * FROM test.debiteur WHERE SORT_NAAM LIKE '%eri%'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $deb_nr['deb_nr'] = $row['DEB_NR']; $deb_naam['name'] = $row['DEB_NAAM']; $deb_adres['adrs'] = $row['DEB_ADRES']; $testje = array_merge($deb_nr, $deb_naam, $deb_adres); $testjevervolg = array('klanten' =&gt; array($testje)); sendResponse(200, json_encode($testjevervolg)); } } </code></pre> <p>This is what it returns:</p> <pre><code>{ "klanten": [ { "deb_nr": "10010", "name": "ERIKA Handelsonderneming", "adrs": "Aan de Heibloem 17" } ] }{ "klanten": [ { "deb_nr": "25071", "name": "Afdeling Heffing &amp; Invordering", "adrs": "Postbus 1275" } ] }{ "klanten": [ { "deb_nr": "25247", "name": "v.d. Heerik b.v.", "adrs": "Flemingstraat 3-5" } ] }{ "klanten": [ { "deb_nr": "25454", "name": "Toering Automatisering", "adrs": "Appelhof 17a" } ] }{ "klanten": [ { "deb_nr": "25601", "name": "Ratering Bouw &amp; Industrie", "adrs": "de Hogenkamp 1" } ] } </code></pre> <p>That is what i get. The problem is, there should be an array of 'klanten' and there should every deb_nr, name and adrs be. Now every thing gets an own 'Klanten' How can is solve this?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload