1

I can't get variables in json format from mysql.

My code:

import mysql_db
import json

# Tüm kullanıcılar çekildi ve  kullanıcı sayısı kadar döndürüldü
tum_kullanicilar = mysql_db.mysql_get_all("select * from users")
for kullanici in tum_kullanicilar:
    print(kullanici['trendyol_api_bilgileri'])

Output:

{
    "api_key": "xxx",
    "api_secret": "xxx",
    "merchant_id": "xxx",
    "default_kargo_id": "2",
    "default_kargo_adi": "MNG Kargo",
    "entegrasyon_durumu": 1,
    "defaultinvoiceAddressId": 659331,
    "defaultshipmentAddressId": 5785842,
    "defaultreturningAddressId": 659321
}

I'm trying to do:

kullanici['trendyol_api_bilgileri']['entegrasyon_durumu']

TypeError: string indices must be integers

6
  • I didn't understand your issue in the code. What is your expected output? Commented Oct 15, 2022 at 2:03
  • I can't get the values ​​inside the json output. Commented Oct 15, 2022 at 2:06
  • So when I try this way, I get an error and when I enter an integer value, it returns values ​​like { or ". kullanici['trendyol_api_bilgileri']['entegrasyon_durumu'] Commented Oct 15, 2022 at 2:07
  • Can you check the type of print(type(kullanici['trendyol_api_bilgileri'])) Commented Oct 15, 2022 at 2:09
  • 1
    Hmm. Output: <class 'str'> Commented Oct 15, 2022 at 2:10

1 Answer 1

1

You need to parse the data with json,

import json

data = json.loads(kullanici['trendyol_api_bilgileri'])
print(data['entegrasyon_durumu'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.