Open HanQingHuI opened 6 years ago
用的是foreach。他本身是一个循环语句。只不过在循环内部需要把获取的值分别赋给数组,再将数组的值赋给string变量。代码如下:
Future<String> getDataFromDB() async {
var pool = new ConnectionPool(
host: 'www.muedu.org',
port: 3306,
user: 'deit-2015',
password: 'deit@2015!',
db: 'project_2015_1',
max: 5);
var results = await pool.query("select pos.name, means.means from words,means,pos where word='" + data + "' and words.ID=means.wordID and means.posID=pos.ID");
String response;
var meanLIST = new Map();
meanLIST[0]=null;
meanLIST[1]=null;
meanLIST[2]=null;
meanLIST[3]=null;
int i=0;
await results.forEach((row) {
response =''' ${row[0]} ${row[1]}''';
meanLIST[i]=response;
i++;
// response=JSON.encode("\u8d44\u6599\uff0c\u6750\u6599");
});
response=JSON.encode([meanLIST[0],meanLIST[1],meanLIST[2],meanLIST[3]]);
return response;
}
貌似处理成list之后仍然无法输出。