Insert c# array in json

I have and array in C# and I need to insert it in json: I have:

int[] a = new int[3];
JObject something=...;

a[0]=12;
a[1]=65;
a[3]=90;

I need something["numbers"].Value="[12,65,90]"

How can I get this?

Jon Skeet
people
quotationmark

It sounds like you really just want to use JArray to wrap the array:

something["numbers"] = new JArray(a);

In other words, let Json.NET take care of the textual representation - you just need to tell it the logical value, which is just an array of numbers. Here's a short but complete example:

using System;
using Newtonsoft.Json.Linq;

public class Test
{
    public static void Main()
    {
        JObject json = new JObject();
        int[] array = { 1, 2, 3 };
        json["numbers"] = new JArray(array);
        Console.WriteLine(json);
    }
}

Output:

{
  "numbers": [
    1,
    2,
    3
  ]
}

people

See more on this question at Stackoverflow