Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tips] How to read Json File With C# in easy tutorial

Friday, 20 November 2015
|
Read: Completed in minutes

[Tips] How to read Json File With C# in easy tutorial

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999.


Read Json File With C# - c# read json file


JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.

How to use c# read json file



These properties make JSON an ideal data-interchange language. JSON is built on two structures:

- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. 

C# is my favorite language, and this will help use do much projects will much uses.
This topic will be help you easy to read JSon file!


Json Format File:

 {
    
    "1": {
        "result":
        {  
            "ITEM_ID":"CNSK",
            "NAME":"C\u1ea9m nang s\u1ef1 ki\u1ec7n",
            "PRODUCT_CODE":"FS",
            "ID_INGAME":"6,1,5572",
            "TYPE":"1",
            "START_TIME":null,
            "END_TIME":null}
        },
        "0":1
    }
    
    -> json["1"].result.ITEM_ID = "CNSK" ;
    -> json["1"].result.NAME = "Cẩm nang sự kiện";
    -> json["1"].START_TIME = "";
    https://learntechtips.com/mda/api/get_itemsIDbyName?NAME=C%E1%BA%A9m%20
    
    
    

Source Code:


    private clsItem GetInfoItemByName(string name)
    {
        // phải có try catch vì khi trả dữ liệu về json[0]            
        try
        { 
    
           clsItem item = new clsItem();
    
           if (name.ToString() == "")
               return null;
    
           string strURL = 
             "https://learntechtips.com/mda/api/get_itemsIDbyName?NAME=" 
             + name + "&PRODUCT_CODE=FS";
          
          var json = GetJSonFromServer(strURL);                
    
          if (json == null)
              return null;
    
    
          if (json["0"] == 0)
              return null;
    
          item.szItemID = json["1"].result.ITEM_ID;
          item.szName = json["1"].result.NAME;
          item.szIdIngame = json["1"].result.ID_INGAME;
          item.szType = json["1"].result.TYPE;
          item.szStartTime = json["1"].result.START_TIME;
          item.szEndTime = json["1"].result.END_TIME;
          item.szProductCode = json["1"].result.PRODUCT_CODE;
    
          return item;
        } catch (Exception ex)
        {            
          
           return null;
        }
    } 
    
    private dynamic GetJSonFromServer(string strUrl)
    {
        try
        {                
            WebClient wb = new WebClient();             
            var data = wb.DownloadString(strUrl);
    
            var json = System.Web.Helpers.Json.Decode(data);                                
            return json;
        }
        catch (Exception ex)
        {                               
             return null;
         }
    }
    

clsItem Class:


public class clsItem
        {
            private string _szItemID;
            private string _szName;
            private string _szProductCode;
            private string _szidIngame;
            private string _sztype;
            private string _szStartTime;
            private string _szEndTime;
    
            public string szEndTime
            {
                get { return _szEndTime; }
                set { _szEndTime = value; }
            }
    
            public string szStartTime
            {
                get { return _szStartTime; }
                set { _szStartTime = value; }
            }
    
            public string szType
            {
                get { return _sztype; }
                set { _sztype = value; }
            }
    
            public string szIdIngame
            {
                get { return _szidIngame; }
                set { _szidIngame = value; }
            }
    
            public string szProductCode
            {
                get { return _szProductCode; }
                set { _szProductCode = value; }
            }
    
            public string szName
            {
                get { return _szName; }
                set { _szName = value; }
            }
           
            public string szItemID
            {
                get { return _szItemID; }
                set { _szItemID = value; }
            }
        }
    

Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about How to read Json File With C# in easy tutorial , please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋  Webzone Tech Tips, all things Tech Tips for web development  - I am Zidane, See you next time soon ✋✋✋✋

🙇🏼🙇🏼 We Appreciate Your Comments and Suggestions - Webzone, all things Tech Tips web development
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com