简体   繁体   中英

json object in ajax jquery request

I have the following HTTP request workload

  {jsonObj={"Nids":"<Id>20</Id><Id>22</Id>","Mids":"\"<Id>337</Id><Id>330</Id><Id>333</Id><Id>335</Id><Id>328</Id>\"","PageNo":"\"3\""}} 

I have the following error Invalid object passed in, \':\' or \'}\' expected

what could be the problem ?

This is not valid JSON. Try:

{jsonObj:{"Nids":"<Id>20</Id><Id>22</Id>","Mids":"\"<Id>337</Id><Id>330</Id><Id>333</Id><Id>335</Id><Id>328</Id>\"","PageNo":"\"3\""}}

replace jsonObj= with jsonObj:

Notice : instead of =

The JsonObj is not valid. The below works.

Use JSON.stringify as much as possible.

> obj='{"jsonObj":{"Nids":"<Id>20</Id><Id>22</Id>","Mids":"<Id>337</Id><Id>330</Id><Id>333</Id><Id>335</Id><Id>328</Id>","PageNo":"3"}}'
'{"jsonObj":{"Nids":"<Id>20</Id><Id>22</Id>","Mids":"<Id>337</Id><Id>330</Id><Id>333</Id><Id>335</Id><Id>328</Id>","PageNo":"3"}}'
> JSON.parse(obj)
{ jsonObj:
   { Nids: '<Id>20</Id><Id>22</Id>',
     Mids: '<Id>337</Id><Id>330</Id><Id>333</Id><Id>335</Id><Id>328</Id>',
     PageNo: '3' } }
>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM