badbyte
badbyte

Reputation: 93

Nesting JSON-Arrays in a json

I'm trying to embed a JArray as a value in a JObject. For the sake of simplicity I have the following string that I'd like to parse: "{"SERVICE":"["ABC"]"}"

And this is my code:

        public static void Main(string[] args)
        {
            JObject jTemp = null;

            string temp = "{\"SERVICE\":\"[\"ABC\"]\"}";
            jTemp = JObject.Parse(temp);
            Console.ReadLine();
        }

An exception is being thrown when trying to parse the string pointing to the letter A of "ABC". The exception message is: "After parsing a value an unexpected character was encountered: A. Path 'SERVICE', line 1, position 14."

I hope that someone can point out my mistake, or at least what am I missing here.

Upvotes: 0

Views: 59

Answers (1)

Rob
Rob

Reputation: 11788

Your array is currently a string:

string temp = "{\"SERVICE\":\"[\"ABC\"]\"}";

Try changing it to this:

string temp = "{\"SERVICE\":[\"ABC\"]}";

Upvotes: 4

Related Questions