-2

I try to get data in json format like this

[{month: 'July',data: [14]}, {month: 'June', data: [3]}, {month: 'May', data: [4]  }]

I try this code

[WebMethod]
    public static string summarydata()
    {

        try
        {
            TrackDataEntities1 sd = new TrackDataEntities1();
            var data = new TrackDataEntities1().spsumdata()
            .Select(s => new { month = s.Month, data = new int[] { s.data.Value } }).ToArray();

            return Newtonsoft.Json.JsonConvert.SerializeObject(data);

        }
        catch (Exception)
        {
            throw new Exception();
        }

    }

When i check console data is like this

[{"month":"July","data":[14]},{"month":"June","data":[3]},{"month":"May","data":[4]}]

whereas i want like this

[{month: 'July',data: [14]}, {month: 'June', data: [3]}, {month: 'May', data: [4]  }]
user6628729
  • 323
  • 1
  • 7
  • 25

1 Answers1

0

A json attribute or string is always defined with double quotes, only doubles, ints or any other non-string value hasn't quotes.

Maxim DC
  • 5
  • 9