Link to home
Start Free TrialLog in
Avatar of jackjohnson44
jackjohnson44

asked on

c# turn string into an object (deserialize)

hi, I have the attached text file.  I can't change it's format in any way.  I need to turn it into a c# object (like a list).  How do I do this?


the file will show a representation of this:
{
    "totalpages": "2",
    "currpage": "1",
    "totalrecords": "1012",
    "filteredrecords": "None",
    "recordcount": "1012",
    "rows": [
        {
            "GroupByDesc": "",
            "Name": "The Name<br> 2701 Ming Avenue",
            "Address": "2701 Ming Avenue",
            "City": "Bakersfield",
            "State": "California",
            "Country": "United States of America",
            "IndexRecordNum": null,
            "LatestInspDate": "",
            "CbiId": "277605"
        },
        {
            "GroupByDesc": "",
            "Name": "The Name<br> 1233 W Avenue P",
            "Address": "1233 W Avenue P",
            "City": "Palmdale",
            "State": "California",
            "Country": "United States of America",
            "IndexRecordNum": null,
            "LatestInspDate": "",
            "CbiId": "277607"
        }
    ]
}

GetLocationSelectorGridData.txt
Avatar of fritzfrancis
fritzfrancis
Flag of United States of America image

This is a Json string. You can use the .NET Framework's DataContractJsonSerializer or you can use a third-party library like NetwonSoft or CodeTitans.Json.
Avatar of jackjohnson44
jackjohnson44

ASKER

Hi, yes it is  Json string.  I have been having issues getting an answer to this question.

People have mentioned using that before but I could not get it to work.  I also can't use thrid party tools.  I don't have access to anything but the string in the file that I attached.  I can't change the way that I get it, the data contract, or anything else.  It is a blackbox web service and for my purposes it isn't important that it originally came from a webservice.  I have a long string as input (the text file).

I need a function that will behave like this:
private static object DoSomethign(string myInputString)

I appreciate everyone's help, but I really need a solution with code.  I have been working on this for a long time and am not making progress.  Thanks!
More specifically:

private static Dictionary<string, string> DoSomethign(string myInputString)

ASKER CERTIFIED SOLUTION
Avatar of fritzfrancis
fritzfrancis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial