我正在尝试在 andorid 列中导入 Mysql 列这是我的 php 文件,它获取列值它向我显示所有这样的记录
[{"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”并仅插入第一条记录时,我的问题就在这里,我不明白我想存储所有行的问题在哪里?
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());
}