Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
React-Native Escape Character
function escapeCharAndroid(url, body) {
return fetch(url, { // Use your url here
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
body: JSON.stringify(body)
.then(response => response.text()) // Convert to text instead of res.json()
.then((text) => {
if (Platform.OS === 'android') {
text = text.replace(/\r?\n/g, '').replace(/[\u0080-\uFFFF]/g, ''); // If android , I've removed unwanted chars.
return text;
.then(response => JSON.parse(response)); // Parse the text.
Copy link

pranavrajs commented Dec 19, 2016

Use this function as a wrapper to your api calls.

Copy link

michaelcv commented Aug 31, 2020

4 years later and your function is still useful. Thanks, I was blocked in a parsing nightmare until I found your solution !

Copy link

pranavrajs commented Sep 1, 2020

@michaelcv Glad, it helped, but I honestly don't remember what it does. 😄 However, I remember it was something related to encoding issues in ASP webservers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment