Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将JSON解析为文件_C#_Android_Json - Fatal编程技术网

C# 将JSON解析为文件

C# 将JSON解析为文件,c#,android,json,C#,Android,Json,我正在为Android编写应用程序,并且有Json解析器 我将其解析为字符串,但我需要将其解析为文件.txt,例如 我怎么能做到 代码: private async Task<JsonValue> FetchAsync(string url) { // Create an HTTP web request using the URL: HttpWebRequest request = (HttpWebRequest)HttpWebReques

我正在为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;
专用异步任务FetchAsync(字符串url)
{
//使用URL创建HTTP web请求:
HttpWebRequest请求=(HttpWebRequest)HttpWebRequest.Create(新Uri(url));
request.ContentType=“application/json”;
request.Method=“GET”;
//将请求发送到服务器并等待响应:
使用(WebResponse=await request.GetResponseAsync())
{
//获取HTTP web响应的流表示形式:
使用(Stream=response.GetResponseStream())
{
//使用此流构建JSON文档对象:
JsonValue jsonDoc=wait Task.Run(()=>JsonObject.Load(stream));
//动态数据=JObject.Parse(jsonDoc[15].ToString);
WriteLine(“响应:{0}”,jsonDoc.ToString());
//返回JSON文档:
返回jsonDoc;

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

如果我的文件位于项目的根目录上,我需要在文件路径中编写什么?是的,只是文件名
StreamWriter sw = new StreamWriter (filepath);
sw.Write(json);
sw.Close();