Here is a JSONArray I have:
[{"items_id":"13","total":"1"}, {"items_id":"216","total":"0"},{"items_id":"16","total":"1"}]
Sometimes, each object has more than two properties (attributes?). But I am just showing the principle here. In Java, I only need to grab "total". I don't need "items_id".
I assume it shows up because here is my MySQL query in PHP:
$count_query_result=mysql_query("
SELECT items.items_id,
COUNT(ratings.item_id) AS total
FROM `items`
LEFT JOIN ratings ON (ratings.item_id = items.items_id)
WHERE items.cat_id = '{$cat_id}' AND items.spam < 5
GROUP BY items_id ORDER BY TRIM(LEADING 'The ' FROM items.item) ASC;");
Here is my JSON output (I have only displayed one of three queries above):
print(json_encode(array($output,$output2,$output3)));
I only want three properties encoded in JSON (one in each of the three output variables). I want the properties "total", "rate" ,and "item".
So my question is, can I get rid of the unneeded items_id property? Or do I even NEED to? (I know I need it in the SQL to make the query work -- but how can I remove it in the JSONArray?)
I am thinking if I have a list with hundreds or thousands of items, I can save half the space (and time?) by only outputing the JSON property I need -- is this thinking correct?
Edit: More code as requested:
while($row=mysql_fetch_assoc($count_query_result))
$output[]=$row;
while($row=mysql_fetch_assoc($average_query_result))
$output2[]=$row;
while($row=mysql_fetch_assoc($items_query_result))
$output3[]=$row;
print(json_encode(array($output,$output2,$output3)));
mysql_close();