Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with my PHP Webservice not giving valid JSON
    primarykey
    data
    text
    <p>I'm using the Class "mysql2json" to make my Json.</p> <pre><code>&lt;?php class mysql2json{ static public function getJSON($resultSet,$affectedRecords){ mb_internal_encoding("UTF-8"); $numberRows=0; $arrfieldName=array(); $i=0; $json=""; //print("Test"); while ($i &lt; mysql_num_fields($resultSet)) { $meta = mysql_fetch_field($resultSet, $i); if (!$meta) { }else{ $arrfieldName[$i]=$meta-&gt;name; } $i++; } $i=0; $json="{\n\"data\": [\n"; while($row=mysql_fetch_array($resultSet, MYSQL_NUM)) { $i++; //print("Ind ".$i."-$affectedRecords&lt;br&gt;"); $json.="{\n"; for($r=0;$r &lt; count($arrfieldName);$r++) { $json.="\"$arrfieldName[$r]\" : \"$row[$r]\""; if($r &lt; count($arrfieldName)-1){ $json.=",\n"; }else{ $json.="\n"; } } if($i!=$affectedRecords){ $json.="\n},\n"; }else{ $json.="\n}\n"; } } $json.="]\n};"; return $json; } } ?&gt; </code></pre> <p>The problem is I'm getting a not valid JSON error in Xcode (iPhone App) and the JSON validator is saying there is an error on line 11 of the results even though line 11 is blank.</p> <p>Validator: <a href="http://jsonlint.com/" rel="nofollow">http://jsonlint.com/</a></p> <p>Here is a sample URL. </p> <p><a href="http://leafseed.com/webservice.php?upc=1116102338" rel="nofollow">http://leafseed.com/webservice.php?upc=1116102338</a> </p> <p>Xcode Error:</p> <pre><code>2012-01-11 08:55:46.137 GroceryVine[6476:bf03] -JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=10 \"Garbage after JSON\" UserInfo=0x9bbabc0 {NSLocalizedDescription=Garbage after JSON} </code></pre> <p>Validator Error</p> <pre><code>Parse error on line 11: ...." } ]}; --------------------^ Expecting 'EOF', '}', ',', ']' </code></pre> <p>Any Ideas? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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