Hello,

There was such a problem. I receive 2 types of JSON responses from the 1st request:

{ "records": { "Guid": "7095be52-8375-445c-922e-66d2aee17509", "ID": "35", "IDFPARTSTEP": "2", "IDFPARTSTEP_NAME": "IDF PART 2", "REQUESTOR": "dgsdg", "REQUESTOR_USER_ID": "ddsgsdg", "REQUESTOR_PHONE": "+3423", "REQUESTOR_BUSINESS_NAME": "sdgsdgsdgs", "REQUESTORDEPARTNAME": "gsdsdg", "INDUSTRYFOCUSGROUP": "asfasa", "LEGALENTITYID": "asfas", "REQUESTORLOCATION": "asfas", "MANAGER": "qfqwf" } } 

And this:

 { "records": { "Guid": "ae169d0d-5bef-4cae-aca6-0b94a9fc5d91", "ID": "48", "LICENSE_ID": "4", "LICENSE_ID_NAME": "qwrqwrq", "PAYMENT_NUM": "KZNB-666", "BUYER_ID": "41", "BUYER_ID_NAME": "fsafefa", "BUYER_BANK": "77", "BUYER_BANK_NAME": "BTA BANK CJSC", "BUYER_ACC": "KZ68934501", "SELLER_ID": "21", "SELLER_ID_NAME": "dqwdrqw", "SELLER_BANK": "41", "SELLER_BANK_NAME": "SIAULIU BANKAS AB", "SELLER_ACC": "qrdwrqwdr", "PAYMENT_SUM": "12000", "PAYMENT_CURR": "840", "PAYMENT_CURR_NAME": "USD", "PAYMENT_DATE": "05.04.2016" } } 

The task is to parse the values ​​of all variables into a one-dimensional array. For example, for the first array it should look like this:

 I1="7095be52-8375-445c-922e-66d2aee17509", I2="35", I3="2", I4="IDF PART 2" и т.д. 

And for the second:

 I2="ae169d0d-5bef-4cae-aca6-0b94a9fc5d91", I2="48", I3="4", I4="qwrqwrq" и т.д. 

The problem is that the names of the fields that I want to get are different. I just need to write down each result in sequence. How is this possible to implement?

  • If the fields come in a different order - do you have to write down how they came or how the previous ones were written down? - Monk
  • Fields should be simply written as came. Ie I5 after the first response should be "KZNB-666", and after the second "dgsdg". Before that, to parse the answer I used. [Field name], but this is not suitable, because the field names are different. - Maxim Shinkarev

1 answer 1

Load your json into a string ( str in the example), connect the assembly to Newtonsoft

  using Newtonsoft.Json.Linq; var parsed = JToken.Parse(str); var array = parsed.OfType<JProperty>() .Select(c => c.Value.Value<string>()).ToList(); 

Everything, in array we have just linear enumeration of values ​​of properties. Maybe it can be easier, right now on the knee just looked at how it lies inside.