Answer to Question #43970 in AJAX | JavaScript | HTML | PHP for umesh

Question #43970
chk this code and please inform me why its happening..
\i have to access "strProduct" and "numPrice" values so..


var objQuotations = {
"vendors": [
{
"strVendor": "V1",
"objQuotation": {
[
{"strProduct": "Soap", "numPrice": "40"},
{"strProduct": "Vanish", "numPrice": "80"},
{"strProduct": "Bicuit", "numPrice": "25"}

]
}
}

]
}
1
Expert's answer
2014-07-08T08:49:17-0400
Method 1.Assign the property.   

varobjQuotations = {
"vendors":[
{
"strVendor":"V1",
"objQuotation":{"products":
[
{"strProduct":"Soap", "numPrice": "40"},
{"strProduct":"Vanish", "numPrice": "80"},
{"strProduct":"Biscuit", "numPrice": "25"}

]
}
}

]
}

The Productand price information can be accessed like this:

alert("Product: "+objQuotations.vendors[0].objQuotation.products[0].strProduct+"\n"+
"Price:"+objQuotations.vendors[0].objQuotation.products[0].numPrice)

Method 2.Change the project to the array.

var objQuotations = {
"vendors": [
{
"strVendor": "V1",
"objQuotation":
[
{"strProduct": "Soap","numPrice": "40"},
{"strProduct": "Vanish","numPrice": "80"},
{"strProduct": "Biscuit","numPrice": "25"}

]

}

]
}

The Productand price information can be accessed like this:

alert ("Product:"+objQuotations.vendors[0].objQuotation[0].strProduct+"\n"+
"Price:"+objQuotations.vendors[0].objQuotation[0].numPrice);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS