简体   繁体   中英

How to retrive json data from sql table column into as a separate table

I have customer table with columns names
"orderid", "body", "time",

Below is the JSON data in side "body" column: {"PersonTitle":"Mr","FirstName":"david","LastName":"ford","PhoneNumber":""} .

How do i get the select data with column names orderid,firstname,phonenumber?

you should persist can come from an external source or generated through serialization from instances of objects.For sample;

 foreach (var c in countries)
    {
  // Serialize the C# object to JSON
  var json = JsonConvert.SerializeObject(c)
  // Save content to the database
  record.JsonColumn = json;
}

You can use Entity Framework (ORM), as well, to save JSON data into one column of a database table. For sample;

DECLARE @json NVARCHAR(MAX)
SET @json='{"PersonTitle":"Mr","FirstName":"david","LastName":"ford","PhoneNumber":"":["SQL","C#","MVC"]}';

SELECT *
FROM OPENJSON(@json);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM