将JSON解析为文件

时间:2015-10-18 20:46:40

标签: c# android json

我为Android编写应用程序并拥有Json解析器

我将其解析为字符串,但我需要将其解析为文件,例如.txt。

我怎么做?

代码:

 private async Task<JsonValue> FetchAsync(string url)
    {
        // Create an HTTP web request using the URL:
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
        request.ContentType = "application/json";
        request.Method = "GET";

        // Send the request to the server and wait for the response:
        using (WebResponse response = await request.GetResponseAsync())
        {
            // Get a stream representation of the HTTP web response:
            using (Stream stream = response.GetResponseStream())
            {
                // Use this stream to build a JSON document object:
                JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
                //dynamic data = JObject.Parse(jsonDoc[15].ToString);
                Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());


                // Return the JSON document:
                return jsonDoc;

我在C#,Xamarin上编写应用程序

1 个答案:

答案 0 :(得分:0)

StreamWriter sw = new StreamWriter (filepath);
sw.Write(json);
sw.Close();