Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSON / Array Parsing 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
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
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Hi

SouthBeach said:
I have the following object
Huh ? If you already have an object, then why are you trying to parse it ?
Code:
[b]var[/b] jjson[teal]=[/teal]obj[teal];[/teal]

Feherke.
feherke.ga
 
Talk about asked and answered!

Thank you @feherke ....

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top