1. 程式人生 > >C#從json檔案中讀取內容

C#從json檔案中讀取內容

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string jsonfile = "C:\\Users\\zhang\\Desktop\\JsonTemplate\\向量瓦片服務.json";
            using (System.IO.StreamReader file = System.IO.File.OpenText(jsonfile))
            {
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject o = (JObject)JToken.ReadFrom(reader);
                    string a = o["ordersId"].ToString();
                    string b = o["userName"].ToString();
                    var c = o["goodsList"];
                }
            }
        }
    }
}