Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36
  1. #31
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Quote Originally Posted by jmrker View Post
    Error message line is in RED above.
    Try replacing JSON.parse(str) with JSON.stringify(manifest)

    alert expects a string and str is already a string where JSON.parse converts it to an object which the alert is then unable to process as the object does not have a toString() method.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  2. #32
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Question

    Quote Originally Posted by joesimmons View Post
    I asked for Pastebin, but ok.

    Anyways... I get no errors in my error console. I created an html file and ran it directly with Firefox 23.0. It alerts an object, for me. I'm not sure what the problem could be on your end.
    Checked version and it is 22.0 of Firefox.

    Changed last post from:
    Code:
    /* this version does not seem to work for the "parse" part */
      str = JSON.stringify(manifest);  document.getElementById('debugDIV').innerHTML += '<p>'+str;  // this line works ok
      alert( JSON.parse(str) );  // unexpected character error on this line
    /* */
    to:
    Code:
    /* this version does not seem to work for the "parse" part */
      str = JSON.stringify(manifest);  document.getElementById('debugDIV').innerHTML += '<p>'+str;  // this line works ok
      alert( JSON.parse(manifest) );  // unexpected character error on this line
    /* */

    In the first, the alert says [object Object].

    On the second, there is no alert, but the error console reports
    Timestamp: 8/10/2013 7:51:56 PM
    Error: SyntaxError: JSON.parse: unexpected character
    Source File: file:///C:/Users/Owner/Desktop/HTMLtest.html
    Line: 41
    My goal is to determine how the manifest setting could be used if it were stored into a text file via the JSONstringify function
    and reloaded to be at a later time of by a different program.

    Currently I am able to save the manifest string in a JSON format
    but I don't see how it can be decoded to become active again as a variable.

  3. #33
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts
    Quote Originally Posted by felgall View Post
    Try replacing JSON.parse(str) with JSON.stringify(manifest)

    alert expects a string and str is already a string where JSON.parse converts it to an object which the alert is then unable to process as the object does not have a toString() method.
    Thanks for the suggestion. I tried that in post #32 with little joy.
    I guess I just don't fully understand the parse function as it relates to a JSON object.

  4. #34
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    You have it backwards: JSON.parse() is used to convert a *STRING REPRESENTATION* into a set of JavaScript objects.

    Again, as Felgall said, to convert a network of objects to a string--the OPPOSITE action--you use JSON.stringify.

    You do not NEED and do not WANT to use JSON.parse() for this...at all.

    Simply:
    Code:
      str = JSON.stringify(manifest);
      alert( str );
    You can't alert( ) the results of JSON.parse() in any meaningful way.
    Last edited by Old Pedant; 08-11-2013 at 01:57 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  5. #35
    New Coder
    Join Date
    Jan 2013
    Location
    Florida
    Posts
    75
    Thanks
    2
    Thanked 0 Times in 0 Posts
    joe -

    for some reason your last variation on the equivalent code was easier for me to understand :
    var str = manifest.a.filename + '\n' + manifest.a.aphorism + '\n' + manifest.a.dog;
    alert(str);
    and i think i get it now. the alert itself is executing JS (\'n') as it reads the value. and so, the alert has 3 lines.

    as far as why don't i try watching a basic JS course on youtube, that makes me smile. i have downloaded and gone thru the JS courses and lessons from : the new boston, adam khoury, stephan mischook, derek banas, code academy, jream, tutor4u, some of w3schools sections, some parts of developer.mozilla, and 2 or 3 others that i don't remember because i recently deleted them for space. i have made DVD's of several series and watched them over and over (even played them while sleeping in hopes of absorption). and not just watched them, watched them on one screen and wrote and tested the code on another screen in notepad++ as i went along. but even having done all that, i don't blame you for thinking i am brand new at this. i am old at studying the subject, but a dunce at actually learning it.

    however, those lessons (and 1 or 2 brilliant (to me anyway) tips from this forum months ago) have been enough for me to set up a working website, which uses a fair amount of JS, that i am proud of.

    the reason i posted the question about terminology (Object, key, property, value) is that, the most ingenious part of my site, the part that was given to me here by xelawho in january, is the ONLY part i don't understand and didn't write myself. and i am beginning to believe that that tip is really at the center of what JS is all about, and i want to know it.

    well, that was a lot of yakking wasn't it ?
    Last edited by pratto; 08-11-2013 at 03:08 AM.

  6. #36
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    I'm glad you want to learn, that's awesome.

    And yes, once you can grasp that JavaScript is an object oriented language, things will become much easier.


 
Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •