Wsparcie The Movie Database

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 odpowiedzi (strona 1 z 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'])

Nie możesz znaleźć filmu lub serialu? Zaloguj się, aby go utworzyć.

Globalny

s zaznacz pasek wyszukiwania
p otwórz menu profilu
esc Zamknij otwarte okno
? otwórz okno skrótów klawiszowych

On media pages

b go back (or to parent when applicable)
e przejdź do strony edycji

On TV season pages

(prawa strzałka) przejdź do następnego sezonu
(lewa strzałka) przejdź do poprzedniego sezonu

On TV episode pages

(prawa strzałka) przejdź do następnego odcinka
(lewa strzałka) przejdź do poprzedniego odcinka

On all image pages

a otwórz okno dodawania obrazu

On all edit pages

t open translation selector
ctrl+ s prześlij formularz

On discussion pages

n otwórz nową dyskusję
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r odpowiedz na dyskusję
l przejdź do ostatniej odpowiedzi
ctrl+ enter wyślij swoją wiadomość
(prawa strzałka) następna strona
(lewa strzałka) poprzednia strona

Ustawienia

Want to rate or add this item to a list?

Zaloguj