這是一些在WP7項目中使用時只會失敗(編譯)的代碼。僅當在WP7項目中使用JSON.NET時出錯
var tree = JObject.Parse(Json);
var temp =
from t in tree.Root["dates"].Children()
select new Schedule {DateString = (string) t["date_string"]};
這是一個WP7.1項目,我現在用的JSON.NET dll是:
... \包\ Newtonsoft.Json.4.0.5 \ LIB \ SL4-windowsphone71 \ Newtonsoft .Json.dll
這裏是我發現裏面溫度異常:
'System.Collections.Generic.IEnumerable<Test.Models.Schedule>' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Test.Models.Schedule>' could be found (are you missing a using directive or an assembly reference?)
的 「VAR樹= JObject.Parse(JSON);」線解析json字符串並且沒有問題地構建樹。
確切的代碼在Monodroid和C#庫項目(具有適當的JSON.NET構建)中完美運行。
任何想法?
謝謝。
不知道爲什麼這被拒絕 - 我花了一個小時搜索錯誤和各種JSON.NET職位。我嘗試了一些變化,甚至在上述的其他項目類型中。如果我錯過了一些明顯的事情,請在評論中指出爲什麼不只是投票。 – IUnknown 2012-01-28 02:02:40
你有'使用System.Linq;'在你的代碼的頂部? – keyboardP 2012-01-28 02:13:37
@keyboardP是的。這裏是我的包括:使用System.Collections.Generic;使用System.IO的 ; 使用System.Linq的; 使用Newtonsoft.Json.Linq; 使用Test.Models; 使用Newtonsoft.Json; – IUnknown 2012-01-28 02:17:03