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 4560120
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:53:09+00:00 2026-05-21T17:53:09+00:00

I am having trouble accessing certain properties in an object that I receive as

  • 0

I am having trouble accessing certain properties in an object that I receive as JSON from a server-side script, as the result of an AJAX call that I am making. My JSON data can come in one of two forms, depending on the data in the object itself.

Form 1:

        "MY_OBJ" : { "FILE" : "myfile.txt",
        "PARAMS" : { "PARAM" : { "KEY" : "mykey",
                "VALUE" : "myvalue"
              } }
          }

Form 2:

        "MY_OBJ" : { "FILE" : "myfile.txt",
        "PARAMS" : { "PARAM" : [ { "KEY" : "mykeyone",
                  "VALUE" : "myvalueone"
                },
                { "KEY" : "mykeytwo",
                  "VALUE" : "myvaluetwo"
                }
              ] }
          }

This is how I am currently trying to parse the data to display in the browser:

    function(v) {
var myFormattedData = v.FILE;
if (v.PARAMS !== undefined && v.PARAMS.PARAM !== undefined &&  v.PARAMS.PARAM.KEY !== undefined && v.PARAMS.PARAM.VALUE !== undefined) {
    myFormattedData += '<br />' + v.PARAMS.PARAM.KEY + ' : ' + v.PARAMS.PARAM.VALUE;
} }

This method works fine when my data is in Form 1. In that situation I will get output in the browser like…

myfile.txt
mykey : myvalue

…which is exactly what I want.

However, when the data is in Form 2 all I get is the file name displayed in the browser like this…

myfile.txt

… but what I am trying to get is something like…

myfile.txt
mykeyone : myvalueone
mykeytwo : myvaluetwo

I need to be able to handle getting the data in both forms. What’s worse is that I probably also should plan for the possibility of receiving more than just one or two key-value pairs at some point in the future. I have been struggling with this for a long time. Any help is much appreciated!

Thank you!

  • 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-21T17:53:10+00:00Added an answer on May 21, 2026 at 5:53 pm

    Try doing something like this for the second form:

    for(i=0;i<v.PARAMS.PARAM.length;i++) {
       myFormattedData += '<br />' + v.PARAMS.PARAM[i].KEY + ' : ' + v.PARAMS.PARAM[i].VALUE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble accessing the fields of a scala object from java. Scala: object
I'm having trouble accessing variable from an object. The object is coming from an
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
I am having trouble accessing the data field. I receive the error: Databinding methods
CakePHP Newbie :) I am having trouble accessing another controller and passing that data
I'm having trouble accessing springSecurityService from resources.groovy file, I'm trying to load user locale
I am having some trouble accessing a stateful session bean (SFSB) from an application
I am having trouble accessing a Javascript function from my code behind file. I
I'm having trouble accessing a dataset. I've pulled data from an Access database (successfully
I'm having trouble accessing a PHP page on my server through a symbolic link

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.