解析JSON到文件

本文关键字:文件 JSON 解析 | 更新日期: 2023-09-27 18:18:18

我正在为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;

解析JSON到文件

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