Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6222319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:17:38+00:00 2026-05-24T08:17:38+00:00

I need your help with the json structure !! (I know it’s easy but

  • 0

I need your help with the json structure !! (I know it’s easy but I cann’t figure what the error is).

in this code I’m having a json file that contains a list of items (say restaurants) along with some details for each branch, like the address. In my js file I’m trying to print all the addresses that match specific item id.

I will post a sample of the json file and the js code to access it.

here is the json file:

{
"items" : 
[

{
"item_id" :"204","details" :[{"country":"usa","city":"NY", "address":"bla bla bla"},{"country":"usa","city":"NY", "address":"another bla bla bla for the same id"}]
},
{
"item_id" :"234","details" :[{"country":"usa","city":"NY", "address":"another bla bla bla"}]
}

]
}

and here is the js code to access that file:

.....
success:function(data){
        $.each(data.items, function(i,item){
                if (item.item_id == 204 ) {
            $("#results").append("<hr/>");
                $("#results").append("<span class='result' >" + item.details.address + "</span><br/>");
    }
      });
    }, ....

but it doesn’t print any thing.

What do you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:17:39+00:00Added an answer on May 24, 2026 at 8:17 am

    You don’t actually need to use $.each in this case, because you have an array of objects i.e. [{}, {}, {}] is an array of objects, even though you actually have an object of arrays of objects :p. Each object has a specified index i.e. “item” whereas each array of objects has a default index of 0,1,2 etc.

    Also yeah, because you have an array of address object details, you need to access them via details[0] or details[1]

    Check this example out on jsFiddle

    for(var i =0;i<data.items.length;i++) {
    
    if (data.items[i].item_id == "204" ) {
                $("#results").append("<hr/>");
                    $("#results").append("<span class='result' >" + data.items[i].details[0].address + "</span><br/>");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ive being trying to cope with this problem but still. I need your help.
I really need your help for this. I am relatively new to programming and
I need your help to resolve a conflict between Tapestry and JaxB. The error
I need your help to understand this better. This is my case. I have
Need your help, trying to change this script: https://github.com/MrHus/jquery-monthly-ical To load external JSON data
I need your help, i'm stacked on this project. When i run my applicaion
I need your help in this case: I have: 1 11 111 Cat1 a,b,c
Kindly need your help as this really taking me long time to try. From
I know that given enough time I'll figure this out, but it sure would
I need your help, For example I have a decimal type variable and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.