JSON: How to parse the JSON string which contains “object”:“page”

前端 未结 1 796
栀梦
栀梦 2021-01-26 10:54

We receive JSON data from Facebook Real Time subscription. The JSON itself contains property like \"object\":\"page\" and we need to access this property.

{
   \         


        
1条回答
  •  孤独总比滥情好
    2021-01-26 11:25

    Use @object:

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

    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.

    Sample fiddle.

    0 讨论(0)
提交回复
热议问题