2017-04-18 39 views
0

我需要使用python re在下面的輸出中獲得令牌的值。可能有人請幫助我我怎樣才能得到「令牌」字符串在下面的輸出使用python 2.7正則表達式

我需要得到下面的字符串:

eyJhbGciOiJIIkpXVCJ9.eyJpc3MiOiIxOWQzODdmZC1kMjA2LTQzNDYtOGRhNy1lMjRkNDZlMWZjZDgiLCJleHAiOjE0OTMwNTA1MxNH0.JBiPb0x4pg_lQXxEV-rbd27qvgm9Q` 

輸出:

{"token":"eyJhbGciOiJIIkpXVCJ9.eyJpc3MiOiIxOWQzODdmZC1kMjA2LTQzNDYtOGRhNy1lMjRkNDZlMWZjZDgiLCJleHAiOjE0OTMwNTA1MxNH0.JBiPb0x4pg_lQXxEV-rbd27qvgm9Q","refresh_token":"639d4-b4e0-4c-8645-229b9e73a394","expires_in":604800,"user":{"id":"19d-d206-43-8da7-e2cd8","username":"tej123","email":"[email protected]","enabled":true,"updated_email":null,"last_login_at":"2017-04-17T16:14:26.520Z"}} 
+1

如何使用正確的工具的工作 - JSON解析器? ('json.loads(..)[「token」]') – SuperSaiyan

回答

1

嘗試:

import json 
j = json.loads('{"token":"eyJhbGciOiJIIkpXVCJ9.eyJpc3MiOiIxOWQzODdmZC1kMjA2LTQzNDYtOGRhNy1lMjRkNDZlMWZjZDgiLCJleHAiOjE0OTMwNTA1MxNH0.JBiPb0x4pg_lQXxEV-rbd27qvgm9Q","refresh_token":"639d4-b4e0-4c-8645-229b9e73a394","expires_in":604800,"user":{"id":"19d-d206-43-8da7-e2cd8","username":"tej123","email":"[email protected]","enabled":true,"updated_email":null,"last_login_at":"2017-04-17T16:14:26.520Z"}}') 
print(j['token']) 
+0

謝謝你的工作 –

相關問題