none
Convert JSON string to C# object RRS feed

  • Question

  • How can i convert this string to JSON object so i can use it in C#?

       var REA = REA ? REA : {};
       REA.initialState = {
           "pageData": {
               "data": {
                   "prettyUrl": "sold/property-apartment-vic-melbourne-105094068",
                   "standard": false,
                   "midtier": true,
                   "featured": false,
                   "lister": {
                       "website": "http://www.melcorp.com.au",
                       "phoneNumber": "03 9663 1117",
                       "_links": {}
                   },
                   "_links": {
                       "prettyUrl": {
                           "href": "https://www.realestate.com.au/sold/property-apartment-vic-melbourne-105094068"
                       },
                       "googleMap": {
                           "templated": true,
                           "href": "https://services.realestate.com.au/services/listings/105094068/map/static?width={width}&height={height}&scale={scale}"
                       },
                       "nearbySchools": {
                           "templated": true,
                           "href": "https://school-service.realestate.com.au/closest_by_type/?lat=-37.80721664&lon=144.96234131{&count}"
                       },
                       "adCall": {
                           "templated": true,
                           "href": "https://sasinator.realestate.com.au/rea/hserver/site=rea/area=sold.details/proptype=apartment/constructionStatus=established/sub=melbourne/state=vic/pcode=3000/price=300k_400k/platform={platform}/version={version}/pos={position}/size={size}/viewid={viewId}/random={random}"
                       },
                       "marketInfo": {
                           "href": "https://investor-api.realestate.com.au/states/Vic/suburbs/Melbourne.json"
                       },
                       "short": {
                           "href": "http://www.realestate.com.au/105094068"
                       },
                       "self": {
                           "href": "https://services.realestate.com.au/services/listings/105094068"
                       },
                       "contactAgent": {
                           "href": "https://agent-contact.resi-agent.realestate.com.au/contact-agent/listing/105094068"
                       }
                   },
                   "signature": false,
                   "constructionStatus": "established",
                   "channel": "sold",
                   "description": "Location is everything & you can do no better than this stylish apartment positioned in one of Melbourne's premium CBD precincts with RMITat your doorstep,easy access to Queen Vic market with in a few min stroll city living has never been more enjoyable. It offers double bedroom with built in robes,separate study easily converts to  a 2nd bedroom,spacious & well presented bathroom, bright modern kitchen includes quality stainless steel smeg appliances & adjoins a generous size living area opening to a sunny private balcony terrace with stunning views to Melbourne's west.Resort style facilities complete a perfect place to work & play including professional gym, heated in-ground pool, Spa/Sauna & tennis court. Entertaining is easy with outdoor BBQ area & cinema, additional features include 24/7 security, intercom system. Leased until Feb 09. Ideal opportunity to generate immediate income.Open Monday to Friday 8:30am - 5:30pm, Saturday 10am - 1pm (this Saturday only) Sunday 12pm - 4pm.",
                   "advertising": {
                       "region": "",
                       "priceRange": "300k_400k"
                   },
                   "title": "*A Perfect Place To Call Home*",
                   "showAgencyLogo": true,
                   "listers": [{
                       "website": "http://www.melcorp.com.au",
                       "phoneNumber": "03 9663 1117",
                       "_links": {},
                       "powerProfile": false
                   }],
                   "features": {
                       "general": {
                           "bedrooms": 2,
                           "bathrooms": 1,
                           "parkingSpaces": 0
                       }
                   },
                   "price": {
                       "display": "$338,000",
                       "abbreviated": "338K"
                   },
                   "propertyType": "apartment",
                   "productDepth": "midtier",
                   "calculator": {
                       "_links": {
                           "callToAction": {
                               "href": "https://visualidentity.cachefly.net/realestate.com.au.calculators.vi.com.au/all-brands/au/com/vi/app/html/index.html?calculator=sold&sponsor=rea&premiumProperty=false&postcode=3000&suburb=Melbourne&state=Vic&channel=sold&displayPrice=$338,000"
                           }
                       },
                       "brandingColors": {
                           "text": "#e4002b",
                           "primary": "#ffffff"
                       },
                       "subtitle": "Calculate repayments for this property",
                       "title": "Mortgage Calculator"
                   },
                   "images": [{
                       "uri": "/e8432fb4aee9b61bf7cf143e54e7c21c33d464b797ea518c4d0c31d5b9eeb8eb/image2.jpg",
                       "name": "photo",
                       "server": "https://i2.au.reastatic.net"
                   }, {
                       "uri": "/98db8c4db4c9529de598b6be35c1b0d231d4074d43f6e1c7ba4ab956135877aa/image3.jpg",
                       "name": "photo",
                       "server": "https://i2.au.reastatic.net"
                   }, {
                       "uri": "/f115ffa46bdcac0d5ee23793a0d1d9371829b16d3f3c484f7bd816dd37518fe5/image4.jpg",
                       "name": "photo",
                       "server": "https://i2.au.reastatic.net"
                   }, {
                       "uri": "/468711161bc2c18f7b34fafca3dafecd850a73d1731d537763a78e8edb6650ff/image5.jpg",
                       "name": "photo",
                       "server": "https://i2.au.reastatic.net"
                   }],
                   "address": {
                       "streetAddress": "483 Swanston Street",
                       "postcode": "3000",
                       "locality": "Melbourne",
                       "suburb": "Melbourne",
                       "location": {
                           "latitude": -37.80721664,
                           "longitude": 144.96234131
                       },
                       "postCode": "3000",
                       "state": "Vic",
                       "subdivisionCode": "Vic",
                       "showAddress": true
                   },
                   "classicProject": false,
                   "agency": {
                       "agencyId": "XIQTUU",
                       "website": "http://www.melcorp.com.au",
                       "address": {
                           "streetAddress": "477 Swanston Street (Cnr Swanston & Franklin Streets)",
                           "postcode": "3000",
                           "suburb": "Melbourne",
                           "state": "Vic"
                       },
                       "phoneNumber": "03 9663 1117",
                       "_links": {
                           "agencyProfile": {
                               "href": "https://www.realestate.com.au/agency/melcorp-real-estate-melbourne-XIQTUU"
                           },
                           "agencyProfileWebview": {
                               "href": "https://www.realestate.com.au/agency/melcorp-real-estate-melbourne-XIQTUU?template=webview"
                           }
                       },
                       "brandingColors": {
                           "secondary": "#ffffff",
                           "text": "#ffffff",
                           "primary": "#00588F"
                       },
                       "name": "Melcorp Real Estate - Melbourne",
                       "logo": {
                           "images": [{
                               "server": "https://i2.au.reastatic.net",
                               "name": "square small agent logo",
                               "uri": "/agencylogo/XIQTUU/50x40/20171129114331.gif"
                           }, {
                               "server": "https://i2.au.reastatic.net",
                               "name": "square medium agent logo",
                               "uri": "/agencylogo/XIQTUU/69x53/20171129114332.gif"
                           }, {
                               "server": "https://i2.au.reastatic.net",
                               "name": "square large agent logo",
                               "uri": "/agencylogo/XIQTUU/84x63/20171129114332.gif"
                           }, {
                               "server": "https://i2.au.reastatic.net",
                               "name": "square agent logo",
                               "uri": "/agencylogo/XIQTUU/13/20171129114332.gif"
                           }, {
                               "server": "https://i2.au.reastatic.net",
                               "name": "small",
                               "uri": "/agencylogo/XIQTUU/11/20171129114331.gif"
                           }, {
                               "server": "https://i2.au.reastatic.net",
                               "name": "default",
                               "uri": "/agencylogo/XIQTUU/2/20171129114331.gif"
                           }, {
                               "server": "https://i2.au.reastatic.net",
                               "name": "large",
                               "uri": "/agencylogo/XIQTUU/12/20171129114331.gif"
                           }],
                           "links": {
                               "small": "/agencylogo/XIQTUU/11/20171129114331.gif",
                               "default": "/agencylogo/XIQTUU/2/20171129114331.gif",
                               "square small agent logo": "/agencylogo/XIQTUU/50x40/20171129114331.gif",
                               "large": "/agencylogo/XIQTUU/12/20171129114331.gif",
                               "square agent logo": "/agencylogo/XIQTUU/13/20171129114332.gif",
                               "square medium agent logo": "/agencylogo/XIQTUU/69x53/20171129114332.gif",
                               "square large agent logo": "/agencylogo/XIQTUU/84x63/20171129114332.gif"
                           }
                       },
                       "email": "sales@melcorp.com.au",
                       "branded": true
                   },
                   "isSoldChannel": true,
                   "isBuyChannel": false,
                   "signatureProject": false,
                   "propertyFeatures": [{
                       "features": ["Swimming Pool - Inground", "Tennis Court"],
                       "section": "outdoor",
                       "label": "Outdoor Features"
                   }, {
                       "features": ["Indoor Spa", "Air Conditioning", "Alarm System", "Intercom"],
                       "section": "indoor",
                       "label": "Indoor Features"
                   }],
                   "listingId": "105094068",
                   "mainImage": {
                       "uri": "/bd3c1b4088431fd55c3d97424fa446de734b2461f8eb300a861750d7fd757a5a/main.jpg",
                       "name": "main photo",
                       "server": "https://i2.au.reastatic.net"
                   },
                   "modifiedDate": {
                       "value": "2015-05-25T02:54:42Z"
                   },
                   "dateSold": {
                       "display": "01 Nov 2008",
                       "value": "2008-11-01"
                   },
                   "generalFeatures": {
                       "parkingSpaces": {
                           "label": "Parking Spaces: 0",
                           "type": "parkingSpaces",
                           "value": 0
                       },
                       "bathrooms": {
                           "label": "Bathrooms: 1",
                           "type": "bathrooms",
                           "value": 1
                       },
                       "bedrooms": {
                           "label": "Bedrooms: 2",
                           "type": "bedrooms",
                           "value": 2
                       }
                   },
                   "isRentChannel": false,
                   "status": {
                       "type": "sold",
                       "label": "Sold"
                   }
               },
               "alternateLink": {
                   "show": true
               }
           },
           "toggles": {
               "feature": {},
               "debug": {}
           },
           "seoLinks": null
       };


    Tuesday, February 27, 2018 10:49 AM

All replies

  • Try the following if you have first validated the json is good to go.

    http://json2csharp.com/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, February 27, 2018 1:23 PM
    Moderator
  • How do i know if it's valid? The script is actually on a web page in a script tag, which i scrapped and tried to make use of it in C#. Is it do-able?
    Tuesday, February 27, 2018 1:45 PM
  • How do i know if it's valid? The script is actually on a web page in a script tag, which i scrapped and tried to make use of it in C#. Is it do-able?

    Google validate json e.g. you get one like this

    https://jsonlint.com/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, February 27, 2018 2:03 PM
    Moderator
  • You don't need a web site. Just copy the JSON to the clipboard then go to a file in Visual Studio and use "Edit" | "Paste Special" | "Paste JSON As Classes". You will then get (if I count correctly) 49 classes. Copy the JSON beginning with the "{" after initialState and up to the last "}" excluding the ":".

    You need to add a reference for Newtonsoft.Json but it is not clear to me whether you need to use Nuget to do that; you probably do need to use Nuget.

    Then use the JsonConvert Class to read the JSON; see Serializing and Deserializing JSON.



    Sam Hobbs
    SimpleSamples.Info


    Wednesday, February 28, 2018 12:00 AM
  • Hello wll6568,

    Be more clear about VS feature you could see here.

    https://stackoverflow.com/questions/21611674/how-to-auto-generate-a-c-sharp-class-file-from-a-json-object-string/34274199#34274199

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 28, 2018 9:15 AM
    Moderator
  • In my response (below here or maybe above here) I said:

    Copy the JSON beginning with the "{" after initialState and up to the last "}" excluding the ":".

    And that applies to websites such as what Karen suggested. The JDON is valid if you do that. You can use any of multiple websites to do it or you can use VS as I described. I know the JSON is valid if you do it as I described because I did it using VS before posting my first response. If that is not what you need then please clarify.



    Sam Hobbs
    SimpleSamples.Info

    Wednesday, March 7, 2018 6:55 AM