且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSON:如何解析包含"object"的JSON字符串:

更新时间:2023-01-17 16:47:33

使用@object:

dynamic result = JsonConvert.DeserializeObject<dynamic>(jsonRealTimeNotification);
string objectType = result.@object.ToString();    

这与指定常规 verbatim标识符时使用的语法相同.从 C#语言规范,第2.4.2节标识符(C#):

This is the same syntax as is used when specifying a regular verbatim identifier. From the C# Language Specification, § 2.4.2 Identifiers (C#):

使用前缀"@"可以将关键字用作标识符,这在与其他编程语言进行接口时非常有用.字符@实际上不是标识符的一部分,因此该标识符在其他语言中可能被视为普通标识符,没有前缀.带有@前缀的标识符称为逐字标识符.

The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.

示例小提琴.