Using. NET core to read the JSON file configuration

Source: Internet
Author: User

1. Use vs2017 to create a single application program

2. Execute commands using the Package Manager console Install-package Microsoft.aspnetcore-version 2.0.1

3. Create a JSON file in the directory

4. The JSON file created by default will not be compiled into the bin directory, all the property pages to modify the JSON file, change the build operation to "content", copy the output directory to "always copy"

5. Run the following code to execute

usingSystem;usingMicrosoft.Extensions.Configuration;namespacejsonconfigsample{classProgram {Static voidMain (string[] args) {            varBuilder =NewConfigurationbuilder (); Builder. Addjsonfile ("Json1.json"); varConfiguration =Builder.            Build (); Console.WriteLine ($"name:{configuration["Name"]} age:{configuration["Age"]}");        Console.readkey (); }    }}

6. Effect of execution

Using. NET core to read the JSON file configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.