簡體   English   中英

如何在 jQuery 中使用 utf-8 字符搜索 JSON,如 SQL LIKE %value% 語句

[英]How to search a JSON with utf-8 characters in jQuery like SQL LIKE %value% statement

我有帶有 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);

最后通過簡單地在頁面中放置一個元標記來解決它

<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM