我試圖使用PhantomJS在飛行中加載一些cookie,但出現一些錯誤。這裏是我的代碼:無法在JSON中的Phantomjs中添加cookie
上面的代碼拋出以下異常:
incompatible type of argument(s) in call to addCookie(); candidates were
addCookie(QVariantMap)
我敢肯定,這裏有一個簡單的解決方案,但我有一個大腦凍結。我的印象是JSON.stringify
從JSON對象返回一個字符串。令人困惑的是,當我將它打印到控制檯時,它看起來與將它存儲爲String
完全相同。我的數據是這樣的:
{"domain": ".sweatytacobo.com",
"expires": "Tue, 10 Jun 2014 16:37:46 GMT",
"expiry": ,
"httponly": false,
"name": "__utmz",
"path": "/",
"secure": false,
"value": "268881515.13222266.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"}
而且當我使用上面的字符串時,它添加沒有問題。那麼爲什麼我的JSON.Stringify
會給我帶來問題?
編輯:
按照PhantomJS source code的addCookie的意見傳遞的格式QVariantMap:
{
* "name" : "cookie name (string)",
* "value" : "cookie value (string)",
* "domain" : "cookie domain (string)",
* "path" : "cookie path (string, optional)",
* "httponly" : "http only cookie (boolean, optional)",
* "secure" : "secure cookie (boolean, optional)",
* "expires" : "expiration date (string, GMT format, optional)"
* }
所以我不應該是能夠以某種方式傳遞一個JSON對象?
是的,我忘了這個。但是當我添加這行代碼時,它仍然會拋出異常。 –