INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

JSON / Array Parsing

JSON / Array Parsing

(OP)
I cannot tell you how many times I've done this ... today, like a couple of other things, I cannot get it to work.

I have the following object

CODE

[
{
"name":"AAA",
"message":"msg 1",
"days":"5",
"cost":"304.40",
"qnumber":"",
"jnumber":"",
"saveit":""
},
{
"name":"BBB",
"message":"msg 2",
"days":"4",
"cost":"285.91",
"qnumber":"20160926",
"jnumber":"333333",
"saveit":""
},
{
"name":"CCC",
"message":"msg 3",
"days":"3",
"cost":"2,355.08",
"qnumber":"4404556211619",
"jnumber":"12345",
"saveit":""
},
{
"name":"DDD",
"message":"msg 4",
"days":"3",
"cost":"525.20",
"qnumber":"201612181538",
"jnumber":"",
"saveit":""
}
] 
My script looks like this

CODE

var jjson=JSON.parse(obj);
        dataObject=obj; var tlist=''; 
        $('#rfqgridROWS').empty();
        for(var i = 0; i < jjson.length; i++) {
            var data = jjson[i];
            tlist+='<tr id="row'+i+'" class="datarow">';
            tlist+='<td>'+data.carrierName+'</td>';
            tlist+='<td>'+data.message+'</td>';
            tlist+='<td>'+data.days+'</td>';
            tlist+='<td>'+data.cost+'</td>';
            tlist+='<td>'+data.qnumber+'</td>';
            tlist+='<td>'+data.jnumber+'</td>';
            tlist+='<td style="font-size: 16px; text-align: center;"><li class="fa fa-save"></li></td>';
            tlist+='</tr>';
        }
        $('#rfqgridROWS').html(tlist); 

I've tried changing var jjson=JSON.parse(obj); to var jjson=JSON.parse(obj[0]);

both syntax give me this error

JSON.parse: unexpected character at line 1 column 2 of the JSON data


What gives?

--
SouthBeach
http://www.fp2php.com
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

RE: JSON / Array Parsing

Hi

Quote (SouthBeach)

I have the following object
Huh ? If you already have an object, then why are you trying to parse it ?

CODE --> JavaScript ( fragment )

var jjson=obj; 

Feherke.
feherke.ga

RE: JSON / Array Parsing

(OP)
Talk about asked and answered!

Thank you @feherke ....

--
SouthBeach
http://www.fp2php.com
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close