2012-01-28 13 views
0

這是一些在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構建)中完美運行。

任何想法?

謝謝。

+0

不知道爲什麼這被拒絕 - 我花了一個小時搜索錯誤和各種JSON.NET職位。我嘗試了一些變化,甚至在上述的其他項目類型中。如果我錯過了一些明顯的事情,請在評論中指出爲什麼不只是投票。 – IUnknown 2012-01-28 02:02:40

+0

你有'使用System.Linq;'在你的代碼的頂部? – keyboardP 2012-01-28 02:13:37

+0

@keyboardP是的。這裏是我的包括:使用System.Collections.Generic;使用System.IO的 ; 使用System.Linq的; 使用Newtonsoft.Json.Linq; 使用Test.Models; 使用Newtonsoft.Json; – IUnknown 2012-01-28 02:17:03

回答

0

在我的WP7應用程序,我用下面的代碼讀取JSON:

JsonTextReader jtr; 
jtr = new JsonTextReader(new StringReader(e.Result)); 

也許,將工作?

+0

我不認爲這會在我的情況下工作,因爲我需要一個樹到Linq結束和JsonTextReader是一個非緩存只向前閱讀器 – IUnknown 2012-01-28 02:20:03

相關問題