How to parse a JSON array of objects in C#

后端 未结 2 1180
失恋的感觉
失恋的感觉 2020-12-22 14:11
{
   \"jsonstring\": [

  {
     \"id\":\"01\",
     \"language\": \"Java\",
     \"edition\": \"third\",
     \"author\": \"Herbert Schildt\"
  },

  {
     \"id\":         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 14:37

    In .NET you can use JavaScriptSerializer. First you will need to create a class that has the same structure as the json string.

    Example:

    {
        "Id":"07",
        "Language": "C++"
    }
    
    
    public class CSharpObject
    {
        int Id {get; set;}
        string Language {get; set;}
    }
    
    
    string json = HttpUtility.HtmlDecode(jsonString);
    JavaScriptSerializer json_serializer = new JavaScriptSerializer();
    CSharpObject csharpObject = (CSharpObject)json_serializer.Deserialize(json);
    

提交回复
热议问题