讀取專案本身的檔案並沒有想像中的簡單,參考了網路上的教學,然後再使用Json.Net 再將他反序列化,就可以取得專案中demo.txt的Json資料。
WP7_Project為組件名稱。
public class RootObject
{
StreamResourceInfo info = Application.GetResourceStream(newUri(@"/WP7_Project;component/demo.txt", UriKind.Relative));
StreamReader reader = newStreamReader(info.Stream, System.Text.Encoding.Unicode);
string jsonString = reader.ReadToEnd();
}
List<RootObject> jsonList = JsonConvert.DeserializeObject<List<RootObject>>(jsonString);
public class RootObject
{
publicstring Product { get; set; }
publicstring Industry { get; set; }
}
參考資料:
http://stackoverflow.com/questions/3920971/how-do-i-embed-and-read-a-text-file-ina-wp7-app