我有這樣的代碼:'的RTServer-id`轉向'的RTServer - id`在java字符串處理
public void foo(){
String script =
"var aLocation = {};" +
"var aOffer = {};" +
"var aAdData = " +
"{ " +
"location: aLocation, " +
"offer: aOffer " +
" };" +
"var aClientEnv = " +
" { " +
" sessionid: \"\", " +
" cookie: \"\", " +
" rtserver-id: 1, " +
" lon: 34.847, " +
" lat: 32.123, " +
" venue: \"\", " +
" venue_context: \"\", " +
" source: \"\"," + // One of the following (string) values: ADS_PIN_INFO,
// ADS_0SPEED_INFO, ADS_LINE_SEARCH_INFO,
// ADS_ARROW_NEARBY_INFO, ADS_CATEGORY_AUTOCOMPLETE_INFO,
// ADS_HISTORY_LIST_INFO
// (this field is also called "channel")
" locale: \"\"" + // ISO639-1 language code (2-5 characters), supported formats:
" };" +
"W.setOffer(aAdData, aClientEnv);";
javascriptExecutor.executeScript(script);
}
我有兩個問題:
- 當我調試,並複製
script
值我看到一個會員rtserver - id
而不是rtserver-id
怎麼可能?該代碼因此拋出異常。
即使我刪除此rtserver-id
成員(並沒有拋出的異常)
我在這個瀏覽器控制檯評估aLocation
並獲得"variable not defined"
。怎麼會這樣?
我不希望'rtserver-id'成爲一個有效的標識符。你確定這實際上與Java有什麼關係?如果您只是想要有效的JSON,請嘗試將它放在引號中......如果您在演示問題是將腳本轉移到Javascript執行程序還是其他內容後顯示* minimal *示例,這將會很有幫助。 – 2015-02-11 12:53:45
我會試試。但我怎麼能解釋,即使沒有這個問題的成員,我仍然無法通過瀏覽器控制檯訪問這些變量? – 2015-02-11 14:26:44