Iterating over JSON object in C#

后端 未结 3 1821
死守一世寂寞
死守一世寂寞 2020-11-28 05:05

I am using JSON.NET in C# to parse a response from the Klout API. My response is like this:

[
  {
    \"id\": \"5241585099662481339\",
    \"displayName\":          


        
3条回答
  •  时光取名叫无心
    2020-11-28 05:48

    You can use the JsonTextReader to read the JSON and iterate over the tokens:

    using (var reader = new JsonTextReader(new StringReader(jsonText)))
    {
        while (reader.Read())
        {
            Console.WriteLine("{0} - {1} - {2}", 
                              reader.TokenType, reader.ValueType, reader.Value);
        }
    }
    

提交回复
热议问题