Created
December 19, 2016 14:09
-
-
Save pranavrajs/66bccee3f8ba100742a1273db6f587af to your computer and use it in GitHub Desktop.
React-Native Escape Character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} |
4 years later and your function is still useful. Thanks, I was blocked in a parsing nightmare until I found your solution !
@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
Use this function as a wrapper to your api calls.