The Movie Database Support Forum

Hello,

I'm trying desperately to display json code in python3. How to convert the variable 'data' in json, to not have a 'print (data)' with a big block of text?

cordially

3 Antworten (Seite 1 von 1)

Jump to last post

Hi there,

I am not familiar with Python so I won't be able to help much. Unless someone who is familiar with it happens to see this post you probably won't get much help here. For coding specific issues, I recommend heading over to a site like Stack Overflow who is a better source for help.

Ok, thank you for answering me. Do not understand how JSON works or have a lot of results. I did a program, without any pretension. I post the other if we have the same problem.


print("type data = "+str(type(data)) )
chaine = str(data.decode('utf8')) 
comptTab=0
ch2=''
ii=0
while ii < len(chaine):
    if (chaine[ii]==','):
        if (chaine[ii+1] == '\"' ):
            ch2+=",\n"
            ch2+=("\t"*comptTab)

    elif (chaine[ii] == '{' ):
        ch2+="\n"
        ch2+=("\t"*comptTab)
        ch2+="{\n"
        comptTab+=1;
        ch2+=("\t"*comptTab)

    elif (chaine[ii]== '}'):
        ch2+="\n"
        comptTab-=1;
        ch2+=("\t"*comptTab)
        ch2+="}"
        ch2+=("\t"*comptTab)

    else:
        if( chaine[ii] == '\\'): # supprime les \\ et les d\
            if( chaine[ii+1] != '\\'):
                chaine[:-1] 
            else:
                ii = ii +1
        else:
            ch2+=chaine[ii]

    ii = ii +1

print(ch2)

Not sure if I quite get what you're going for either. Load data into json then it's a Python3 dict data structure. Can access data chunks by the keys then.

json_message = json.loads(data)
print(data['stuff'])

Es fehlt ein Film oder eine Serie? Logge dich ein zum Ergänzen.

Allgemein

s Fokus auf Suchfeld
p Profil öffnen
esc Fenster schließen
? Tastenkürzel anzeigen

Videos

b Zurück
e Bearbeiten

Staffeln

Nächste Staffel
Vorherige Staffel

Episoden

Nächste Episode
Vorherige Episode

Bilder

a Poster oder Hintergrundbild hinzufügen

Editieren

t Sprachauswahl öffnen
ctrl+ s Speichern

Diskussionen

n Neue Diskussion erstellen
w Beobachten an / aus
p Diskussion öffentlich / privat
c Diskussion öffnen / schließen
a Diskussionsverlauf anzeigen
r Auf Diskussion antworten
l Letzte Antwort anzeigen
ctrl+ enter Senden
Nächste Seite
Vorherige Seite

Einstellungen

Diesen Eintrag bewerten oder zu einer Liste hinzufügen?

Anmelden