Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I need help to parse below json n create a dynamic dictionary manually instead of Javascriptserializer class as this doesn't work in .net core.

Sample json:
const string json =
"{" +
" \"firstName\": \"John\"," +
" \"lastName\" : \"Smith\"," +
" \"age\" : 25," +
" \"address\" :" +
" {" +
" \"streetAddress\": \"21 2nd Street\"," +
" \"city\" : \"New York\"," +
" \"state\" : \"NY\"," +
" \"postalCode\" : \"11229\"" +
" }," +
" \"phoneNumber\":" +
" [" +
" {" +
" \"type\" : \"home\"," +
" \"number\": \"212 555-1234\"" +
" }," +
" {" +
" \"type\" : \"fax\"," +
" \"number\": \"646 555-4567\"" +
" }" +
" ]" +
" }";

What I have tried:

Sample json:
const string json =
    "{" +
    "     \"firstName\": \"John\"," +
    "     \"lastName\" : \"Smith\"," +
    "     \"age\"      : 25," +
    "     \"address\"  :" +
    "     {" +
    "         \"streetAddress\": \"21 2nd Street\"," +
    "         \"city\"         : \"New York\"," +
    "         \"state\"        : \"NY\"," +
    "         \"postalCode\"   : \"11229\"" +
    "     }," +
    "     \"phoneNumber\":" +
    "     [" +
    "         {" +
    "           \"type\"  : \"home\"," +
    "           \"number\": \"212 555-1234\"" +
    "         }," +
    "         {" +
    "           \"type\"  : \"fax\"," +
    "           \"number\": \"646 555-4567\"" +
    "         }" +
    "     ]" +
    " }";
Posted
Updated 2-Oct-20 8:10am

 
Share this answer
 
At the risk of plugging my own code, here's a small library i made that does precisely that.

Json: A Fairly Powerful JSON Engine in a Small Package[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900