【发布时间】:2020-12-30 14:11:55
【问题描述】:
我有带有 UTF-8 字符的 JSON 数据,我想搜索它类似于 SQL LIKE %value% 语句。
下面是代码 - 当你用英文写名字时它可以正常工作:
jsonData ='[{"id":19,"cost":400,"name":"اسلم","height":198,"weight":35},{"id":21,"cost":250,"name":"ÙØ±ØØ§Ù†","height":216,"weight":54},{"id":38,"cost":450,"name":"علی","height":147,"weight":22}]';
array = JSON.parse(jsonData);
var result = array.filter((x) => x.name.toLowerCase().indexOf("ا") >= 0);
console.log(result);
这是与英文数据相同的代码,它工作正常
jsonData ='[{"id":19,"cost":400,"name":"arian","height":198,"weight":35},{"id":21,"cost":250,"name":"Arkanss","height":216,"weight":54},{"id":38,"cost":450,"name":"Jumla","height":147,"weight":22}]';
array = JSON.parse(jsonData);
var result = array.filter((x) => x.name.toLowerCase().indexOf("r") >= 0);
console.log(result);
【问题讨论】:
标签: javascript jquery utf-8