我使用django庫函數。JsonResponse到數組
my_data = get_stats(request)
get_stats
返回JsonResponse。
return JsonResponse({'data': response})
每個response
對象由'id','name'和'value'組成。我需要將my_data
解析爲數組 - 我需要獲取每個項目的id, name and value
。我怎樣才能做到這一點?
我使用django庫函數。JsonResponse到數組
my_data = get_stats(request)
get_stats
返回JsonResponse。
return JsonResponse({'data': response})
每個response
對象由'id','name'和'value'組成。我需要將my_data
解析爲數組 - 我需要獲取每個項目的id, name and value
。我怎樣才能做到這一點?
JsonResponse
身體處於my_data.content
所以合法是
json.loads(my_data.content)
你的代碼中沒有'data'變量。 –
@vishes_shell謝謝我編輯數據到my_data – Mae
你確定'response'是反對呢?嘗試使用'json.loads(response)'包裝,並且您有對象並使for循環獲取每個id,名稱,值 –
@ F'inAwesome我無法更改'get_stats'函數 - 如果是這樣的話。 – Mae
不......我的意思是你說的ID,名稱,價值的迴應,所以這是解析答覆的方式...... –