2017-12-11 12 views
0

JSON配列でいっぱいのウェブサイトを解凍しています。ボットは、機能テストを呼び出して、私はGET_TEXT印刷する場合、私はこれを持って、各反復についてjson配列を連結します。ユニークなキーを追加する際に問題が発生する

:私はそれらを連結し、すべての列に一意のキーを(以下のコードを参照)を追加しようとしています

{"status":{"code":0,"message":"Ok","user":{"isBanned":false,"isNotConfirmed":false}},"payload":{"vat":0,"price":{"201":{"100":{"batchsize_id":60916,"quantity":100,"product_price":14.12,"shipment_price":8.98,"country_id":"DE"},"200":{"batchsize_id":60922,"quantity":200,"product_price":19.13,"shipment_price":9.06,"country_id":"DE"},"300":{"batchsize_id":60928,"quantity":300,"product_price":23.64,"shipment_price":9.14,"country_id":"DE"},"400":{"batchsize_id":60934,"quantity":400,"product_price":28.4,"shipment_price":9.23,"country_id":"DE"},"500":{"batchsize_id":60940,"quantity":500,"product_price":32.93,"shipment_price":9.32,"country_id":"DE"},"600":{"batchsize_id":60946,"quantity":600,"product_price":37.08,"shipment_price":9.4,"country_id":"DE"},"700":{"batchsize_id":60952,"quantity":700,"product_price":41,"shipment_price":9.48,"country_id":"DE"},"800":{"batchsize_id":60958,"quantity":800,"product_price":44.72,"shipment_price":9.63,"country_id":"DE"},"900":{"batchsize_id":60964,"quantity":900,"product_price":48.24,"shipment_price":9.71,"country_id":"DE"},"1000":{"batchsize_id":60970,"quantity":1000,"product_price":51.59,"shipment_price":9.79,"country_id":"DE"},"minDeliveryDays":5,"maxDeliveryDays":8}},"productionCountry":["DE"],"minDeliveryDays":5,"maxDeliveryDays":8},"pager":{"total":null,"count":null,"current":1}} 

以下のコードはすべての繰り返しを連結し、各配列に一意のキーを追加しようとしています。私は、各アレイの前に列を削除するにはどうすればよい

{'a6a465b1a': '{"status":{"code":0,"message":"Ok","user":{"isBanned":false,"isNotConfirmed":false}},"payload":{"vat":0,"price":{"201":{"100":{"batchsize_id":60916,"quantity":100,"product_price":14.12,"shipment_price":8.98,"country_id":"DE"},"200":{"batchsize_id":60922,"quantity":200,"product_price":19.13,"shipment_price":9.06,"country_id":"DE"},"300":{"batchsize_id":60928,"quantity":300,"product_price":23.64,"shipment_price":9.14,"country_id":"DE"},"400":{"batchsize_id":60934,"quantity":400,"product_price":28.4,"shipment_price":9.23,"country_id":"DE"},"500":{"batchsize_id":60940,"quantity":500,"product_price":32.93,"shipment_price":9.32,"country_id":"DE"},"600":{"batchsize_id":60946,"quantity":600,"product_price":37.08,"shipment_price":9.4,"country_id":"DE"},"700":{"batchsize_id":60952,"quantity":700,"product_price":41,"shipment_price":9.48,"country_id":"DE"},"800":{"batchsize_id":60958,"quantity":800,"product_price":44.72,"shipment_price":9.63,"country_id":"DE"},"900":{"batchsize_id":60964,"quantity":900,"product_price":48.24,"shipment_price":9.71,"country_id":"DE"},"1000":{"batchsize_id":60970,"quantity":1000,"product_price":51.59,"shipment_price":9.79,"country_id":"DE"},"minDeliveryDays":5,"maxDeliveryDays":8}},"productionCountry":["DE"],"minDeliveryDays":5,"maxDeliveryDays":8},"pager":{"total":null,"count":null,"current":1}}'} 

def test(url_final): 
     get_url = requests.get(url_final) 
     #get_dict = json.loads(get_url.text) 
     get_text = get_url.text 
     print(get_text) 
     dictionary['a' + str(uuid.uuid4())[:8]] = get_text 
     print(dictionary) 

printit() 

私の唯一の問題は、「印刷辞書は」私にこれを返すということですか?

+0

なぜ出力が問題になるのですか?あなたの期待とはどのように違いますか? –

+0

あなたの実際の質問は何ですか? [良い質問をするにはどうすればいいですか?](https://stackoverflow.com/help/how-to-ask) – Galen

+0

申し訳ありません、質問を編集しました – KenJ

答えて

0

JSONが期待どおりの辞書ではなく文字列として返されています。文字列をいくつかの値に変換するには、解析する必要があります。あなたは間違った場所にちょうどそこに、正しい呼び出しを持っています。 get_textが入力されたら(より良い名前を考えたい場合があります)、json_values = json.loads(get_text)を実行する必要があります。今すぐjson_valuesにはあなたが期待する辞書が含まれ、get_textの代わりにそれを割り当てることができます。

+0

ありがとう!しかし、今私は新しい問題があります。 Jsonは変更されました。{'aa0f2fb7b':{'payload':{'minDeliveryDays':5 ....}}}ステータスで開始する必要があります。理解できません? – KenJ

+0

object_pairs_hook = OrderedDict、ありがとうございます – KenJ

関連する問題