@manhng

Welcome to my blog!

JSON Is Case Sensitive

July 24, 2019 16:42

JSON (edit)

https://viblo.asia/p/jsonparse-and-jsonstringify-oOVlYWwyK8W

const myObj = {
name: 'Sy Dinh',
age: 22,
social: 'https://sydinh.com/',
};

const myObjStr = JSON.stringify(myObj);

console.log(myObjStr);
// JSON "{"name":"Sy Dinh","age":22,"social":"https://sydinh.com/"}"

console.log(JSON.parse(myObjStr));
// Object {name: "Sy Dinh", age: 22, social: "https://sydinh.com/"}

https://stackoverflow.com/questions/1056121/how-to-create-json-string-in-c-sharp

https://www.c-sharpcorner.com/article/working-with-json-string-in-C-Sharp/

http://antonkallenberg.com/2015/03/13/json-net-case-insensitive-dictionary/

https://completejavascript.com/tim-hieu-ve-json-trong-javascript/

const string = JSON.stringify({name: "X", born: 1990});
console.log(string);
// => {"name":"X","born":1990}

const obj = JSON.parse(string);
console.log(obj.name);
// => X
console.log(obj.born);
// => 1990

Hiá»u và sá»­ dụng JSON trong 10 phút


List<Person> people = new List<Person>
{
    new Person{ID = 1, FirstName = "Scott", LastName = "Gurthie"},
    new Person{ID = 2, FirstName = "Bill", LastName = "Gates"}
};

string jsonString = people.ToJSON();

string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(people[0]);

var details = Newtonsoft.Json.Linq.JObject.Parse(jsonData);

Console.WriteLine(string.Concat("Hi ", details["FirstName"], " " + details["LastName"]));

var person = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(jsonData);

Console.WriteLine(string.Concat("Hi ", person.FirstName, " " + person.LastName));

Convert JSON to XML

October 6, 2018 11:13

Convert JSON to XML (edit)

using Newtonsoft.Json;
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;

namespace Json2Xml
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            ConvertJson2Xml();
            Console.Write("Successfully! Press any key to exit ");
            Console.ReadKey();
        }

        /// 
        /// Convert JSON to XML
        /// https://www.newtonsoft.com/json/help/html/ConvertJsonToXml.htm
        /// 1. Copy JSON from Web API
        /// 2. Format JSON from https://jsonformatter.org/ (replace ["] with [\"])
        /// 3. Convert JSON to XML
        /// 
        private static void ConvertJson2Xml()
        {
            string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string xmlRootFilePath = Path.Combine(desktopFolder, "root.xml");
            string jsonRootFilePath = Path.Combine(desktopFolder, "root.json");
            XmlDocument xmlDoc = new XmlDocument();
            XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            var xmlDeclare = xmlDeclaration.OuterXml;
            string json = File.ReadAllText(jsonRootFilePath);
            XNode node = JsonConvert.DeserializeXNode(json, "root");
            string xmlContent = node.ToString();
            if (!xmlContent.Contains(xmlDeclare))
            {
                xmlContent = xmlContent.Insert(0, Environment.NewLine).Insert(0, xmlDeclare);
            }
            File.WriteAllText(xmlRootFilePath, xmlContent);
        }
    }
}

Sort XML

https://stackoverflow.com/questions/8749480/sort-xml-nodes-by-alpha-numeric-using-c-sharp

JSON Online Tools

Có chức năng view JSON dễ nhìn, trực quan

https://jsoneditoronline.org/

Có chức năng thu gọn JSON trên một dòng code

https://jsonformatter.org/

Share links

May 3, 2018 09:44

Share links edit

75 Important queries in SQL Server every developer should know

http://www.codingfusion.com/post/75-Important-queries-in-SQL-Server-every-developer-should-know

Everywhere JSON so why not in SQL SERVER–New feature in SQL SERVER 2016

https://www.codeproject.com/Articles/1240829/Everywhere-JSON-so-why-not-in-SQL-SERVER-New-featu

Từ khóa

  • Vanilla JavaScript
  • Pure JavaScript

Bài viết

JavaScript Design Patterns: IIFE pattern

https://www.codebyamir.com/blog/javascript-designpattern-iife

Tạo Dropdown list từ JSON và sử dụng AJAX (XMLHttpRequest) + JavaScript hoặc sử dụng jQuery

https://www.codebyamir.com/blog/populate-a-select-dropdown-list-with-json

Ví dụ mẫu về Bootstrap

https://www.codebyamir.com/blog/bootstrap-fundamentals

https://www.codebyamir.com/blog/creating-a-fixed-header-on-a-scroll-event

Hiểu về Web Storage API - Local Storage & Session Storage

https://www.codebyamir.com/blog/web-storage-api-localstorage-sessionstorage

Hiểu về tấn công CSRF

https://www.codebyamir.com/blog/understanding-preventing-csrf

Làm việc với Excel và thư viện EPPlus

https://www.codebyamir.com/blog/create-excel-files-in-c-sharp

Web API AND XML

March 15, 2018 21:27

Code

Ví dụ

http://www.lateral8.com/articles/2010/3/5/openxml-sdk-20-export-a-datatable-to-excel.aspx

<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccountProblem</Code>
<Message>Your Google account is not currently enabled for this operation. Please check https://console.developers.google.com/billing to see if you have a past due balance or if the credit card (or other payment mechanism) on your account is expired. You can find additional information at https://developers.google.com/storage/docs/signup</Message>
<Details>The billing account for the requested project is disabled in state 'closed'</Details>
</Error>

JSON

November 7, 2017 10:09

camelCase JSON Serialized

Install-Package Newtonsoft.Json

Convert object to JSON with camelCase format

var jsonSerializerSettings = new JsonSerializerSettings
{
       ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var json = JsonConvert.SerializeObject(obj, jsonSerializerSettings);

 

Refer:

https://codehollow.com/2017/05/return-json-from-csharp-azure-function/

https://stackoverflow.com/questions/19445730/how-can-i-return-camelcase-json-serialized-by-json-net-from-asp-net-mvc-controll

Categories

Recent posts