【问题标题】:How to search a JSON with utf-8 characters in jQuery like SQL LIKE %value% statement如何在 jQuery 中搜索带有 utf-8 字符的 JSON,如 SQL LIKE %value% 语句
【发布时间】: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


    【解决方案1】:

    最后通过简单地在页面中添加一个元标记来解决它

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

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 2013-08-31
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多