problems decoding json objects

T

Tamer Higazi

Hi people!

My JSON String:

from json.decoder import JSONDecoder


myjs =
'{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":["(e-mail address removed)","mypass"]}'

If I try to decode it, with:

JSD = JSONDecoder()
rsx = JSD.decode(myjs)

I get this error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/json/decoder.py", line 368, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107
- 219)



How do I solve this problem ?!


For any help, thanks



Tamer
 
D

Denis McMahon

Hi people!

My JSON String:

from json.decoder import JSONDecoder
myjs =
'{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},
{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":
["(e-mail address removed)","mypass"]}'

If I try to decode it, with:

JSD = JSONDecoder()
rsx = JSD.decode(myjs)

I get this error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/json/decoder.py", line 368, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107
- 219)
How do I solve this problem ?!
For any help, thanks

Try doing a manual inspection of your json string. It appears to contain
several objects, but they're not contained within an outer object or an
array. If you want a list of data objects, you need to put [] round them.
If you want them to be dictionary elements, you need to wrap them with {}
and put identifiers in. If you want a single dictionary, you need to
remove most of the { and }.

In addition, one of the objects doesn't appear to be terminated.

{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},
{"KontaktTel":["01234","11223344"] ** missing '}' ??? ** ,
{"ZahlungsArt":"0"},
{"ZugangsDaten":["(e-mail address removed)","mypass"]}

Depending how I "correct" the json string, I can create different values
for rsx:

(1) a list of 4 dictionaries:

$ ./jsonerr.py
[{u'APLZ': u'55116', u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName':
u'Tamer', u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz'},
{u'KontaktTel': [u'01234', u'11223344']}, {u'ZahlungsArt': u'0'},
{u'ZugangsDaten': [u'(e-mail address removed)', u'mypass']}]

(2) a single dictionary:

$ ./jsonerr.py
{u'APLZ': u'55116', u'KontaktTel': [u'01234', u'11223344'],
u'ZugangsDaten': [u'(e-mail address removed)', u'mypass'], u'ANName':
u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer', u'AAnschrift':
u'Bauerngasse', u'AOrt': u'Mainz', u'ZahlungsArt': u'0'}

(3) an object with 4 subsidiary objects:

$ ./jsonerr.py
{u'Misc data': {u'ZahlungsArt': u'0'}, u'Name and Addr': {u'APLZ':
u'55116', u'ANName': u'Higazi', u'AHausnr': u'1', u'AVName': u'Tamer',
u'AAnschrift': u'Bauerngasse', u'AOrt': u'Mainz'}, u'Login info':
{u'ZugangsDaten': [u'(e-mail address removed)', u'mypass']},
u'Telephones': {u'KontaktTel': [u'01234', u'11223344']}}

but I have no way of knowing which it is you require.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top