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

  • Home
  • SEARCH
  • 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 7525311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:30:33+00:00 2026-05-30T03:30:33+00:00

I’m pretty new to JSON, javascript, YUI and trying to compelte a homework assignment.

  • 0

I’m pretty new to JSON, javascript, YUI and trying to compelte a homework assignment. I have a JSON packet of the form

[{"id":"1234", "name":"some description","description":"url":"www.sd.com"}, {same format as previous one}]

I tried an example with YUI to pase a jsonString like this:

var jsonString = '{"id":"1234", "name":"some description","description":"url":"www.sd.com"}';
var messages = [];
messages = YAHOO.lang.JSON.parse(jsonString);

then I print out the result in messages[]. In the jsonString example, I get my output. When trying to do it from the professor’s web server, I get a failure on parsing. I’m assming it’s from the way his packet is surrounded by a [] and mine is not in my example. I tried doing

YAHOO.lang.JSON.parse(professorResponse[0]);

and that also returned an error. I was wondering what the best format/practices in this scenario on what to do with something passed back from a web server in terms of how to format the data so I can parse it. I have zero experience in this area and want to get off to a good start. Thanks.

Edit:

To parse the web server's response, I'm doing this:

function sendRequest() {
  var url = "class website&response=JSON";
  var callback = {success:handleResponse, failure:handleFailure, timeout:5000};
  var transaction = YAHOO.util.Connect.asyncRequest("GET", url, callback, null);
}

// this gets called when my handleResponse methods looks if it's JSON vs XML and sees that the server's response is JSON
function parseJSONResponse(response) {
  var messages = [];
  try {
    messages = YAHOO.lang.JSON.parse(response);
  }
  catch (e) {
    alert("JSON parse failed");
    return;
  }
}

I continue to get JSON Parse failed when I try to parse the response.

  • 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-30T03:30:34+00:00Added an answer on May 30, 2026 at 3:30 am

    Both your example and the professor’s are invalid JSON that can’t be parsed because both include a “description” property that doesn’t have a value:

    ... "description":"url":"www.sd.com" ...
    

    Should be:

    ... "description": "somevalue", "url":"www.sd.com" ...
    

    (Or just remove "description":)

    The rest of my answer assumes the above can be fixed before continuing…

    You don’t explain how you are getting your professor’s JSON, or how you generate your output, but in a general sense JSON is a string representation of an object or array, that you then parse to create an actual object or array. Your example is a representation of an object. Your professor’s example is a representation of an array of objects.

    Where you’re going wrong is you seem to be trying to treat professorResponse as an array and access its element 0 with professorResponse[0] before you’ve parsed it, but if it is JSON then it is a string representing an array not an actual array so you need to parse it first:

    // get professorResponse from server somehow
    var professorResponse = '[{"id":"1234", "name":"some description","description":"fixed","url":"www.sd.com"}, {same format as previous one}]';
    
    var parsedResponse = YAHOO.lang.JSON.parse(professorResponse);
    
    // now parsedResponse is an array of objects, so
    parsedResponse.length   // is 2 - there are two elements
    parsedResponse[0]       // is first element, i.e., {"id":"1234", "name":"some description","description":"url":"www.sd.com"}
    parsedResponse[1]       // is second element
    parsedResponse[0].id    // is "1234"
    parsedResponse[0].name  // is "some description"
    

    Note: in your example you initialise messages to refer to an empty array, but then you immediately assign it equal to the return from YAHOO.lang.JSON.parse(jsonString) which in this case will not be an array (because your jsonString represents an object that is not an array) – your original empty array is thrown away.

    “what to do with something passed back from a web server in terms of how to format the data so I can parse it.”

    If the web server is returning valid JSON you don’t need to format it in order parse it – it will already be a string in a format that can be parsed with JSON.parse().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.