Hi
Is there anyway to iterate through a json object and retrieve the name
of the property as well as the value.
For exampe. Imagine this object
{
title: '1',
bedrooms: '2',
bathrooms: '3',
description: '4',
country: '5',
location: '6',
price: '7',
}
I want to loop through it and have a variable that holds title, then
bedrooms then bathrooms.... as well as one that holds 1 then 2 then
3... respectively.
Is that possible?
Thanks 5 1591
Nick S meinte:
Hi
Is there anyway to iterate through a json object and retrieve the name
of the property as well as the value.
What do you mean by "json object"?
For exampe. Imagine this object
{
title: '1',
bedrooms: '2',
bathrooms: '3',
description: '4',
country: '5',
location: '6',
price: '7',
}
I want to loop through it and have a variable that holds title, then
bedrooms then bathrooms.... as well as one that holds 1 then 2 then
3... respectively.
Is that possible?
You are looking for "for ... in". Mind the possible problems with
(augmented) prototypes, though.
Gregor
-- http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie http://web.gregorkofler.com ::: meine JS-Spielwiese http://www.image2d.com ::: Bildagentur für den alpinen Raum
On Sep 5, 2:18 pm, Gregor Kofler <use...@gregorkofler.atwrote:
Nick S meinte:
Hi
Is there anyway to iterate through a json object and retrieve the name
of the property as well as the value.
What do you mean by "json object"?
For exampe. Imagine this object
{
title: '1',
bedrooms: '2',
bathrooms: '3',
description: '4',
country: '5',
location: '6',
price: '7',
}
I want to loop through it and have a variable that holds title, then
bedrooms then bathrooms.... as well as one that holds 1 then 2 then
3... respectively.
Is that possible?
You are looking for "for ... in". Mind the possible problems with
(augmented) prototypes, though.
Gregor
--http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com ::: meine JS-Spielwiesehttp://www.image2d.com :::Bildagentur für den alpinen Raum
err, ok, just forget my crappy grasp of the terminology for a second.
I've outlined the problem pretty clearly. I do use "for...in" but I
can't get to the name of each item. (And if that's not clear I mean
the thing on the left of the colon) :)
Thanks
Nick S meinte:
>--http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com ::: meine JS-Spielwiesehttp://www.image2d.com ::: Bildagentur für den alpinen Raum
Sigh. Please don't quote sigs...
err, ok, just forget my crappy grasp of the terminology for a second.
I've outlined the problem pretty clearly. I do use "for...in" but I
can't get to the name of each item. (And if that's not clear I mean
the thing on the left of the colon) :)
Lets see:
var obj = { ... }, p;
for(p in obj) {
window.alert(obj[p]);
};
Please answer: What is the value of p?
Gregor
-- http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie http://web.gregorkofler.com ::: meine JS-Spielwiese http://www.image2d.com ::: Bildagentur für den alpinen Raum
On Sep 5, 3:10 pm, Gregor Kofler <use...@gregorkofler.atwrote:
Nick S meinte:
--http://photo.gregorkofler.at:::Landschafts- und Reisefotografiehttp://web.gregorkofler.com::: meine JS-Spielwiesehttp://www.image2d.com :::Bildagentur für den alpinen Raum
Sigh. Please don't quote sigs...
err, ok, just forget my crappy grasp of the terminology for a second.
I've outlined the problem pretty clearly. I do use "for...in" but I
can't get to the name of each item. (And if that's not clear I mean
the thing on the left of the colon) :)
Lets see:
var obj = { ... }, p;
for(p in obj) {
window.alert(obj[p]);
};
Please answer: What is the value of p?
Thanks. yes, this is what I do, however, I don't just want the value,
I also want the name of the property.
>
Gregor
--http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com ::: meine JS-Spielwiesehttp://www.image2d.com :::Bildagentur für den alpinen Raum
Nick S meinte:
On Sep 5, 3:10 pm, Gregor Kofler <use...@gregorkofler.atwrote:
>var obj = { ... }, p; for(p in obj) { window.alert(obj[p]);
};
Please answer: What is the value of p?
>
Thanks. yes, this is what I do, however, I don't just want the value,
I also want the name of the property.
Jeez! The value of p *is* the name of the property. obj[p] gives you the
value of the property p.
Gregor
-- http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie http://web.gregorkofler.com ::: meine JS-Spielwiese http://www.image2d.com ::: Bildagentur für den alpinen Raum This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Luke Matuszewski |
last post by:
Welcome
As suggested i looked into JSON project and was amazed but...
What about cyclical data structures - anybody was faced it in some
project ?
Is there any satisactional recomendation...
...
|
by: Kevin Newman |
last post by:
Hello,
I noticed that the JavaScript library for JSON posted on json.org
(http://www.json.org/json.js) is modifying Object.prototype (adding a
method - toJSONString). I thought this was...
|
by: dhtmlkitchen |
last post by:
JSON
We all know what it is.
In ECMAScript 4, there's a JSON proposal:
Object.prototype.toJSONString
String.prototype.parseJSON
The current proposal, String.prototype.parseJSON, returns...
|
by: Jon Paal [MSMD] |
last post by:
using json like
( {"Records": , "RecordCount":"1" } )
and jquery like:
$.ajax({
....
success: function(json, status) {
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |