Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.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中的字符串#_C#_Json_String_Data Conversion - Fatal编程技术网

C# Json转换为c中的字符串#

C# Json转换为c中的字符串#,c#,json,string,data-conversion,C#,Json,String,Data Conversion,这是JSON数据 我怎么能这样呢 XmlTextReader reader = new XmlTextReader("http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"); TextBox1.Text = reader.tostring(); 我对JSON很满意 然后可以编写如下代码 using Sys

这是JSON数据

我怎么能这样呢

XmlTextReader reader = new XmlTextReader("http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo");

TextBox1.Text = reader.tostring();
我对JSON很满意

然后可以编写如下代码

using System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json;

namespace Examples.System.Net
{
    public class WebRequestGetExample
    {
        public static void Main ()
        {
            // Create a request for the URL. 
            WebRequest request = WebRequest.Create (
              "http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo");
            // Get the response.
            WebResponse response = request.GetResponse ();
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader (dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd ();
            // Parse JSON 
            JObject o = JObject.Parse(responseFromServer);
            JArray status= (JArray)o["status"];
            string message = (string)status["message"];
            // Clean up the streams and the response.
            reader.Close ();
            response.Close ();
        }
    }
}

Json不是XML。签出Json.Net Library我的Json字符串将是web服务。。我如何
stringjson=http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo
string json=???请参阅更新的答案。阅读HttpWebRequest/HttpWebResponse/WebClient
var json = new WebClient().DownloadString("http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo");
TextBox1.Text = json;