0
{
    "recsonpage": "1",
    "recsindb": "1",
    "1": {
        "orders.orderid": "84344969",
        "entity.customerid": "19421067",
        "entity.entityid": "84344969",
        "orders.autorenew": "false",
        "orders.endtime": "1572414460",
        "orders.resellerlock": "false",
        "orders.timestamp": "2018-10-30 05:47:41.791511+00",
        "orders.customerlock": "true",
        "entity.entitytypeid": "87",
        "entity.currentstatus": "Active",
        "entitytype.entitytypekey": "dotco",
        "orders.transferlock": "true",
        "orders.creationtime": "1540878460",
        "orders.privacyprotection": "false",
        "entitytype.entitytypename": ".CO Domain Name",
        "orders.creationdt": "1540878459",
        "entity.description": "testlbapi.co"
    },
   "2": {
       "orders.orderid": "84421837",
       "entity.customerid": "19442287",
       "entity.entityid": "84421837",
       "orders.autorenew": "true",
       "orders.endtime": "1573084799",
       "orders.resellerlock": "false",
       "orders.timestamp": "2018-11-06 17:06:25.269568+00",
       "orders.customerlock": "false",
       "entity.entitytypeid": "450",
       "entity.currentstatus": "Active",
       "entitytype.entitytypekey": "dotspace",
       "orders.transferlock": "false",
       "orders.creationtime": "1541523983",
       "orders.privacyprotection": "false",
       "entitytype.entitytypename": ".SPACE Domain Names",
       "orders.creationdt": "1541435012",
       "entity.description": "thairaksaa.space"
   },
  "3": {
       "orders.orderid": "84421838",
       "entity.customerid": "19442287",
       "entity.entityid": "84421838",
       "orders.autorenew": "true",
       "orders.endtime": "1604682389",
       "orders.resellerlock": "false",
       "orders.timestamp": "2018-11-06 17:06:30.199466+00",
       "orders.customerlock": "true",
       "entity.entitytypeid": "3",
       "entity.currentstatus": "Active",
       "entitytype.entitytypekey": "domcno",
       "orders.transferlock": "true",
       "orders.creationtime": "1541523989",
       "orders.privacyprotection": "false",
       "entitytype.entitytypename": ".COM Domain Name",
       "orders.creationdt": "1541435014",
       "entity.description": "thairaksaa.com"
  }
}

I need to get the child data of "1" parent data. I was trying to deserialize this json data but I'm having a problem because the parent data is a number.

UPDATE: How will I get the parent data integer if they are 2 or more? because, on my API, the json data has different number of records depends on customer's order list.

5
  • 1
    Do you have C# classes for this? Can you show them? What library are you using for serialization? JSON.NET? Commented Nov 8, 2018 at 6:12
  • 1
    Possible duplicate of Deserializing JSON with numbers as keys Commented Nov 8, 2018 at 6:16
  • 2
    Welcome to Stack Overflow! Please edit to add meaningful code and a problem description here (see How to Ask). Posting a Minimal, Complete, Verifiable Example that demonstrates your problem would help you get better answers. Thanks! Commented Nov 8, 2018 at 6:18
  • Hi John, below is the library var MyDetails = JsonConvert.DeserializeObject<MyDetail>(json); public class MyDetail { public string recsonpage {get;set;} public string recsindb {get;set;} } Commented Nov 8, 2018 at 6:26
  • Hi krishna, I will check on that . thank you. Commented Nov 8, 2018 at 6:27

1 Answer 1

1

You can try to use json.net to serializat.

If the key contains a special word you can try to use JsonProperty to mark binding key from your JSON.

public partial class JsonModel
{
    [JsonProperty("1")]
    public Dictionary<string, string> obj1 { get; set; }

    [JsonProperty("recsonpage")]
    public string Recsonpage { get; set; }

    [JsonProperty("recsindb")]
    public string Recsindb { get; set; }
}

Then you can use like

var MyDetails = JsonConvert.DeserializeObject<JsonModel>(json);

Note

There are two way can create model easily.

  • You can use Web Essentials in Visual Studio, use Edit > Paste special > paste JSON as a class, you can easier to know the relation between Json and model.

  • If you can't use Web Essentials you can instead of use https://app.quicktype.io/?l=csharp online JSON to Model class.

You can try to use those models to carry your JSON Format.

Sign up to request clarification or add additional context in comments.

11 Comments

Hi D-shih, this is the output after I tried your suggestion recsonpage: 1 recsindb: 1 1: System.Collections.Generic.Dircyionary'2[System.String,System.String]
@IrisLorrenHequibal It work good in c# online dotnetfiddle.net/gBTlmd
Hi @d-shih oh I see. Yes it's working now on my end. Thank you so much!
@IrisLorrenHequibal No problem glad to help you can mark this answer if that help you :)
last question D-shih, since that json does have 1 data, what if it has 2 or more? because my API has more than 1 record depends on the customer's domain list. the one I provided is from a customer that has 1 data.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.