Stringified JSON has unwanted double quotes
Don't stringify things that are not objects. Just use them.
$.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22canberra%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys",function(data) { $(document.body).append("Count: " + data.query.count); $("#heading").append(data.query.results.channel.title);}, "json");
<!DOCTYPE html><html lang="en"> <head> <title>Yahoo Weather for Canberra</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.3.1.js"></script> </head> <body> <h1 id="heading"></h1> </body></html>
Remove double quotes from JSON String
Try to replace "[
with [
and ]"
with ]
json = json.replaceAll("\"\\[","[");
json = json.replaceAll("\\]\"", "]");
How to remove unwanted double quotes when converting CSV to JSON in angular
In the end, I did it this way:
for (var m=0; m<array.length; m++){
array[m].id = array[m].id.substring(1, array[m].id.length-1);
array[m].level = array[m].level.substring(1, array[m].level.length-1);
array[m].date = array[m].date.substring(1, array[m].date.length-1);
}
May not be the best way but it works for me in the current context. Am still looking for ways to improve on this. Thank you!
Dump to JSON adds additional double quotes and escaping of quotes
You are double encoding your JSON strings. data
is already a JSON string, and doesn't need to be encoded again:
>>> import json
>>> not_encoded = {"created_at":"Fri Aug 08 11:04:40 +0000 2014"}
>>> encoded_data = json.dumps(not_encoded)
>>> print encoded_data
{"created_at": "Fri Aug 08 11:04:40 +0000 2014"}
>>> double_encode = json.dumps(encoded_data)
>>> print double_encode
"{\"created_at\": \"Fri Aug 08 11:04:40 +0000 2014\"}"
Just write these directly to your file:
with open('data{}.txt'.format(self.timestamp), 'a') as f:
f.write(data + '\n')
Remove quote from the JSONArray output
1. .replaceAll()
testValue.toString().replaceAll("\"", "");
This method replace all the double quotes which are present in your name not the first and the last.
Example : "Abcd" becomes Abcd but if the name is "Ab"cd" it should be Ab"cd according to your requirement but it becomes Abcd. Mean to say that all the double quote replaced.
2. substring()
If you want to use the substring method approach then use the following syntax to remove the first and the last double quotes from your string:
testValue.toString().subString(1,testValue.toString().length()-1);
1
- indicates the first character of the string
testValue.toString().length()-1
: indicates the last character of the string.
For your case .substring()
method is more better than the .replaceAll()
, if .getString()
not working.
3. .ValueOf() OR .getString()
Don't know In your case why it is not working ? (may be because the string itself containing the quotes) other wise the best way is to Convert the JSONValue to the String as String.ValueOf(testValue);
OR
childJSONObject.getString("name");
Otherwise give preference as : 3 > 2 > 1
How to remove unwanted characters (brackets, quotes, and commas) from a JSON string?
You already have your JSON data in a string, so you need to parse it into a JavaScript object (an array in your case):
JSON.parse(jsonString)
This will give you a data structure that you can iterate over, to extract each item in a clean way.
Here is a demo:
var jsonString = '[ "Monday: 2:00 – 10:00 PM", "Tuesday: 2:00 – 10:00 PM", "Wednesday: 2:00 – 10:00 PM", "Thursday: 2:00 – 10:00 PM", "Friday: 12:00 – 11:00 PM", "Saturday: 12:00 – 11:00 PM", "Sunday: 12:00 – 9:00 PM" ]';
var businessHours = JSON.parse(jsonString);
businessHours.forEach((bizDay) => {
console.log( bizDay );
} );
Related Topics
How to Move Focus on Next Field When Enter Is Pressed
Check If a Number Has a Decimal Place/Is a Whole Number
How to Manipulate a Select Options Based on Another Select Option in HTML
Javascript Check If Values Exist in Array Json
Angular 4: How to Read Content of Text File With Httpclient
Ag-Grid Cellrender With Button Click
How to Change Size of Mat-Icon on Angular Material
Fetch - Missing Boundary in Multipart/Form-Data Post
React Router Not Working After the Page Refresh
Angularjs:Ng-Model Binding Not Updating When Changed With Jquery
How to Add Multiple Values in Json Object and Get an Updated Json File
Filtering Multiple Items With Es6 Array Functions
Click on Pseudo Element Using Selenium
How Could I Get the Latest Date from an Array of Dates - Javascript/Typescript
How to Change Color of Button on Press in React Native
How to Disable Dates Before Today in Jquery Datepicker
Nosuchelementerror: Unable to Locate Element - Selenium Webdriver Using JavaScript