あなたの助けのために短いコードを書きました。これが役立つことを願っています
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Newtonsoft.Json;
using System.Text;
using System.IO;
using System.IO.IsolatedStorage;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
namespace jsontest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
StringBuilder stringBuilder = new StringBuilder();
StringWriter stringWriter = new StringWriter(stringBuilder);
JsonWriter jsonWriter = new JsonTextWriter(stringWriter);
jsonWriter.Formatting = Formatting.Indented;
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("name");
jsonWriter.WriteRawValue("Test");
jsonWriter.WritePropertyName("user");
jsonWriter.WriteValue("T123");
jsonWriter.WritePropertyName("password");
jsonWriter.WriteValue("StackOverFlow123");
jsonWriter.WriteEndObject();
stringWriter.Close();
saveOnFile(stringWriter.ToString());
readFromFile();
}
public void saveOnFile(string data)
{
IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("Test.txt", FileMode.Create, myFile));
sw.WriteLine(data); //Wrting to the file
sw.Close();
}
public void readFromFile()
{
IsolatedStorageFile myFile = IsolatedStorageFile.GetUserStoreForApplication();
try
{
StreamReader reader = new StreamReader(new IsolatedStorageFileStream("Test.txt", FileMode.Open, myFile));
string rawData = reader.ReadToEnd();
reader.Close();
textBlock1.Text = rawData;//use raw data as string of JSON data
}
catch { }
}
}
}
これは動作するコードです。最初に rawData を解析してから JSON オブジェクトとして使用する必要があります