Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Needs to be dynamic since the rows are dynamic. Also cannot use other 3rd party dll since application is .net 3.5. I am using JavaScriptSerializer


JSON
{
 "0": {
        "caseNumber": "###",
        "name": "###, ###",
        "birthYear": "###",
        "caseLocation": "###",
        "caseType": "###",
        "dateFiled": "##/##/##",
        "type": "",
        "query": {
            "firstName": "###",
            "lastName": "###",
            "dateOfBirth": "####-##-##",
            "fileDateBegin": "####",
            "fileDateEnd": "####"
        },
        "color": "###",
        "names": [
            "###, ###"
        ],
        "rank": "###",
        "s": ###
    },
    "1": {
        "caseNumber": "###",
        "name": "###, ###",
        "birthYear": "###",
        "caseLocation": "###",
        "caseType": "###",
        "dateFiled": "##/##/##",
        "type": "",
        "query": {
            "firstName": "###",
            "lastName": "###",
            "dateOfBirth": "####-##-##",
            "fileDateBegin": "####",
            "fileDateEnd": "####"
        },
        "color": "###",
        "names": [
            "###, ###"
        ],
        "rank": "###",
        "s": ###
    },
    "failed": 0
}


What I have tried:

With jsonconvert. But needed to create a stand alone class since application is .net 3.5 framework and doesn't work with newer newtown.json

Tried this but did not get any rows back.
C#
public class SearchIndex
{
    public string caseNumber { get; set; }
    public string name { get; set; }
    public int? birthYear { get; set; }
    public string caseLocation { get; set; }
    public string caseType { get; set; }
    public DateTime? dateFiled { get; set; }
    public string type { get; set; }
    public string color { get; set; }
}
Posted
Updated 12-Feb-24 9:32am
v4
Comments
Richard Deeming 13-Feb-24 4:09am    
"application is .net 3.5"

Any particular reason you can't upgrade to a more recent version? v4.0 was released almost 14 years ago, and v4.5 almost 12 years ago. v3.5 is almost old enough to drink, at least in the UK! :)

Unless you still need to support Windows XP SP2 or Server 2003 SP1, both of which are wildly out-of-date, then 4.x should be fine.

You can use 3rd-party libraries. Newtonsoft.Json[^] supports versions dating back to .Net Framework 2.0. ref: Supported Frameworks[^].

I have written a comprehensive article Working with Newtonsoft.Json in C# & VB[^] that tackles how to use the library and also special cases where custom converters are required.
 
Share this answer
 
You can create a standalone class for your Json using Visual Studio feature. Create an empty C# class, copy your JSON into the clipboard, then use the menu item Edit > Paste Special > Paste JSON As Classes - and you get the C# code for your JSON. Follow the below link to create you class for deserialization. Convert JSON to C# Classes using Paste JSON as Classes Feature[^]
 
Share this answer
 
Comments
[no name] 12-Feb-24 17:53pm    
Needs to be dynamic. Cant lists all the dynamic properties.

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