Home > database >  MongoDB Data Api not decoding emojis or arabic language
MongoDB Data Api not decoding emojis or arabic language

Time:08-29

When I want to store text in Arabic or emojis in database using the Data Api (Rest Api), Mongodb has no problem with it. But when i try to get the arabic text or emojis using, it returns something like this:

"ar":"خدمة تكيي٠الهواء" //ar: Arabic

Please what can I do to resolve this. Below is the code I use to make the request:

static var headers = {
    'Content-Type': "application/json",
    'api-key': APIKEY,
  };

String url = '$MONGODB_BASEURL/app/data-api/endpoint/data/v1/action/find';

    var body = {
      "collection": collection,
      "database": "Database",
      "dataSource": "DatabaseCluster",
      "filter": filter,
      "sort": {sortBy: 1},
      "limit": limit,
      "projection": projection,
    };

 await http
          .post(Uri.parse(url), headers: headers, body: json.encode(body))
          .then((value) {    
        print(value.body); //Gives the same result  
        if (value.statusCode == 200)
          response = json.decode(value.body)['documents']; //Gives the same result  
        else {
          throw Error();
        }
      });

CodePudding user response:

Try it with uft8

 response = utf8.decode(response.bodyBytes)
  • Related