Return Json, but it includes backward slashes “\”,
Why are you returning a json string from your web api?
It knows how to serialize objects into JSON's automatically.
Anyway to convert a string json into a json use JSON.parse
:
var json = "{\"cid\":1,\"model\":\"WT50JB\",\"detail\":\"sdf??\",\"unit\":2,\"time_in\":\"2012-12-11T19:00:00\",\"time_out\":\"2012-12-12T13:00:06.2774691+07:00\",\"time_used_dd\":0.0,\"time_used_hh\":0.0}";
var parsedJSON = JSON.parse(json);
alert(parsedJSON.cid); // 1
How to remove backslash on json_encode() function?
json_encode($response, JSON_UNESCAPED_SLASHES);
Remove Backslashes from Json Data in JavaScript
Your string is invalid, but assuming it was valid, you'd have to do:
var finalData = str.replace(/\\/g, "");
When you want to replace all the occurences with .replace
, the first parameter must be a regex, if you supply a string, only the first occurrence will be replaced, that's why your replace wouldn't work.
Cheers
Remove back slash from Json String in android
The command
result.replaceAll("\\","");
is correct and if you try to display the server response with an online json formatter (https://jsonformatter.curiousconcept.com/) you can clearly see that the string is not correctly formatted. The double quotes after the "response" and one at the end are not required.
How to remove or prevent escape slashes from json-file data in azure logic app workflow
You just need to replace the \" with " by the expression below:
replace(string(body('Get_blob_content')), '\"', '"')
And then we can use json() to convert it.
Update:
In your json data to insert to table storage, the data in red box below cause the problem
You can't insert into it with the second level of data.
Remove back slashes from JSON response
You just need to deserialize the body.
let err = { "_body": "{\"error\":\"264\",\"message\":\"Please enter valid usename/password\",\"object\":null}", "status": 400, "ok": false }
var body = JSON.parse(err._body);console.log(body.message);
Related Topics
Easiest Way to Check If an Arbitrary String Is a Valid Filename
Cast Class into Another Class or Convert Class to Another
Reportviewer: Show Reports in Print Layout With Page Width Zoommode
Choosing the Default Value of an Enum Type Without Having to Change Values
Select Distinct by Two Properties in a List
Find Item in Observablecollection Without Using a Loop
How to Validate a Datetime in C#
How to Remove Illegal Characters from Path and Filenames
File and Line Numbers for Errors Are Not Displaying in the Error List Unless the File Is Open
Console.Writeline Does Not Show Up in Output Window
How to Disable Cursor in Textbox
The Find Element Returns Empty String..Using Xpath Contains,Text()
Deserialize Json String in to Multiple C# Objects
Sorting a Collection Containing Strings And/Or Numbers
Storing Enums as Strings in Mongodb
Convert Time With Milliseconds to Datetime in C#
Asp.Net Core Get Json Array Using Iconfiguration
User.Identity.Getuserid() Returns Null After Successful Login