0
我試圖在Andorid的列導入mysql的塔,這裏是我的PHP文件,該文件得到列的值就顯示我的所有記錄 這樣如何通過所有從結果使用JSCONArray
[{"nome":"A BARATEIRA DE TECIDOS LIMITADA ME"}][{"nome":"A BARATEIRA DE TECIDOS LIMITADA ME"},{"nome":"A.A.L. COMESTIVEIS E RESTAURANTE LTDA ME"}][{"nome":"A BARATEIRA DE TECIDOS LIMITADA ME"},{"nome":"A.A.L. COMESTIVEIS E RESTAURANTE LTDA ME"},{"nome":"ACOUGUE E MERCEARIA COSTELAO DA SERRA LTDA ME"}]"
//我的PHP記錄文件
<?php
mysql_connect("localhost","root","abcd");
mysql_select_db("fabricacao");
$sql=mysql_query("SELECT nome FROM cliente ORDER BY NOME") ;
$nome ='nome';
while($rows=mysql_fetch_assoc($sql))
{
$output[]=$rows;
print(json_encode($output));
mysql_close();
}
?>
我的問題就在這裏,當我將結果記錄到數組,然後JSONArray.lenght(),顯示「大小= 1」和inseting只是第一個記錄,我不明白的地方是問題,我想所有的存儲行?
try
{
JSONArray jArray = new JSONArray(result);
//mydb
sql= openOrCreateDatabase("CLT",SQLiteDatabase.CREATE_IF_NECESSARY,null);
ContentValues values=new ContentValues();
int n = jArray.length();
for(int i=0;i<jArray.length();i++)
{
JSONObject json_data = jArray.getJSONObject(i);
values.put("CLIENT", json_data.getString("nome"));
sql.insert("clnt", null, values);
}
sql.close();
}catch(Exception e)
{
Log.e("Erro",e.toString());
}