Reading Json slash in Javascript [duplicate] - javascript

This question already has answers here:
How can I access object properties containing special characters?
(2 answers)
Closed 7 years ago.
I'm reading a JSON file through javascript. I'm having trouble getting today/_text because of the forward slash. I can get today successfully by doing: {{hours.results[0].today}}. How would I get today/_text? I've tried:
today\/_text
today/\_text
today//_text
today\\/_text
{"offset":0,"results":[{"today/_text":"Today:YES","today/_source":"/hours/1","today":"2,3,4"}]}

hours.results[0]["today/_text"] should do the trick!
hours.results[0] returns an object that has that as a key, making that the easiest way to access the property in question.

Related

Access object key containing character : [duplicate]

This question already has an answer here:
Parsing a JSON object with Special characters in property key
(1 answer)
Closed 3 years ago.
I am pulling in reviews from iOS and the key they have has a : in the middle.
Like so: im:rating: {attributes: {…}}
Therefore, doing something like this is not working. {entry.im:rating.label}
How do I get the label from im:rating?
Simple answer: entry['im:rating'].label

serialized string to form [duplicate]

This question already has answers here:
How to convert URL parameters to a JavaScript object? [duplicate]
(34 answers)
Closed 3 years ago.
I have serialized form in string such as:
"name=Michael&surname=Davies&multiple=selection1&multiple=selection3"
How can I convert this string to object and then change values in form, or directly change values in form with this string? I have several forms in one html page and each string represent values in one form.
Thank you.
Try using below to get an array. Then u can put them in to a JSON object by traversing through the array. May be not the best solution.
$("#form").serializeArray();

How to escape # in javascript to retrive object property [duplicate]

This question already has answers here:
JavaScript property access: dot notation vs. brackets?
(17 answers)
Closed 7 years ago.
i have Javascript object as below.
How can i get value for SERIAL#, like i can retrieve *.INST_ID or *.INSTANCE.
how can i escape # and get the value required.
So far i have tried SERIAL#23% but none helped so far.
var t = {"INST_ID":"1","INSTANCE":"xina","SID":"27","SERIAL#":"48810", "PROGRAM":"Perl#app01"}
console.log(kSess.SERIAL%23); gives syntax error
I am parsing variable "t"
This data is coming from java code, so there is nothing much i can do to change SERIAL# to something else
Any idea?
Try to retrieve the value like this...
t["SERIAL#"]; // will return you the value..
Store it somewhere or play with it as you like. :)

Javascript Turn string into array [duplicate]

This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 7 years ago.
I want to turn this into an array
"["65747add-afd2-45b5-92e0-150bbe40e6d9", "9c247ea5-6b81-4f47-a50c-42367dedd50b", "c1555363-aca9-4e04-8844-e0180397c72e"]"
I am getting it from the page like this:
$('#layout-uuids').text()
Is there away to just get it as an array or do I need to turn the string into an array somehow?
Thanks!
That string looks like JSON. If it is indeed JSON, all you need is JSON.parse():
var someArray = JSON.parse($('#layout-uuids').text());

How do I display a JSON object in a pretty format , on my webpage? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JavaScript data formatting/pretty printer
var theobject_string = '{...}'; // I have a json object as a string.
How can I display this string in a pretty way, on my webpage (html)?
I want this the elements to be indented.
This library does exactly what you're looking for: http://www.cerny-online.com/cerny.js/demos/json-pretty-printing

Categories

Resources