1

I have the following JSON string:

[
   {
      "name":"Test diagnosis",
      "code":"324324",
      "table":"EXAMPLE",
      "addedby":"EDnurse",
      "dateadded":3243243,
      "qualifier":[
         {
            "name":"Qualifier",
            "value":"Confirmed Diagnosis",
            "code":"23434434",
            "prefix":"[C] "
         },
         {
            "name":"Left/Right",
            "value":"Bilateral",
            "code":"324343",
            "suffix":" - Bilateral"
         }
      ],
      "prefix":"[C] ",
      "suffix":" - Bilateral"
   }
]

You can see that the Qualifier field in this JSON String is nested and has 2 objects.

I am working on a package that parses this JSON string using C# in SSIS. I can Parse the string with one object of qualifier, but when I add the second object (left/right), and attempt to turn the string into an array, I receive an error.

Without array (works with one Qualifier object):

Diagnosis diagnosis = js.Deserialize<Diagnosis>(reviewConverted);

With array (returns error stating that I cannot implicitly convert type diagnosis to type diagnosis ):

Diagnosis diagnosis = js.Deserialize<List<Diagnosis>>(reviewConverted);

I also use the following Class to define my diagnosis fields:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SC_8aae662509ae4bab8491323924579173
{
    class Diagnosis
    {
        public string name { get; set; }
        public string code { get; set; }
        public string table { get; set; }
        public string addedby { get; set; }
        public string dateadded { get; set; }

        public qualifier Qualifier { get; set; }

        public string prefix { get; set; }
        public string suffix { get; set; }


    }
}

Here is my qualifier class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SC_8aae662509ae4bab8491323924579173
{
    class qualifier
    {
        public string name { get; set; }
        public string value { get; set; }
        public string code { get; set; }
        public string prefix { get; set; }
    }
}
4
  • 2
    shouldn't your qualifier property in your Diagnosis class be a List<Qualifier> ? Commented Jan 24, 2019 at 10:12
  • can you post the Qualifier class code as well? Commented Jan 24, 2019 at 10:20
  • because it might fail as well due to different properties in the two array objects where in the first it is called prefix and in the second it is called suffix and it will not be able to automatically deserialize it. Commented Jan 24, 2019 at 10:22
  • Added the qualifier class - thanks. Commented Jan 24, 2019 at 10:41

2 Answers 2

1

As far as i can tell, based on what you're saying, 1 Diagnosis object, can contain multiple Qualifier objects. So what you need to do is the following: First, change your Diagnosis class to have the following property:

public qualifier List<Qualifier> { get; set; }

instead of

public qualifier Qualifier { get; set; }

Also the following statement is what gives you an error:

Diagnosis diagnosis = js.Deserialize<List<Diagnosis>>(reviewConverted);

You are trying to store in a Diagnosis objext a List of Diagnosis object, which makes no sense of course.

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

1 Comment

Thank you - this helped.
1

Did you try like below?

class Diagnosis
{
    public string name { get; set; }
    public string code { get; set; }
    public string table { get; set; }
    public string addedby { get; set; }
    public string dateadded { get; set; }

    public List<Qualifier> qualifier { get; set; }

    public string prefix { get; set; }
    public string suffix { get; set; }


}

1 Comment

Thank you for the answer - it helped me towards the solution above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.