Click here to Skip to main content
14,879,544 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Error in jsone.count.
C#
using Newtonsoft;
using Newtonsoft.Json;

jsonr=[{"count":[{"first":1,"second":2,"third":3},{"first":11,"second":22,"third":33},{"first":111,"second":222,"third":333}]}]
            int oo = 0;
            int[,] jsona = new int[100, 9];
            jCount jsone = JsonConvert.DeserializeObject<jCount>(jsonr);
            foreach (var element in jsone.count)
            {
                oo += 1;
                jsona[oo, 1] = element.first;
                jsona[oo, 2] = element.second;
                jsona[oo, 3] = element.third;
            }


C#
public class jCount
    {
        private List<jplace>
    }
    public class jPlace
    {
        public int first { get; set; }
        public int second { get; set; }
        public int third { get; set; }
    }


What I have tried:

I have tried using:
C#
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsone= serializer.Deserialize<List<jcount>>(jsonr);
Posted
Updated 4-Apr-17 16:20pm
v2
Comments
Richard Deeming 4-Apr-17 14:12pm
   
You haven't told us what the error message is.

The code you've posted will not compile, because you seem to have removed parts at random.

The incomplete code in the jCount class suggests you've made the property private, which means you can't access it from outside of that class.

1 solution

public class jCount
        {
            public jPlace[] count { get; set; }
        }
        public class jPlace
        {
            public int first { get; set; }
            public int second { get; set; }
            public int third { get; set; }
        }
        public ActionResult Index()
        {
            string jsonr = "[{\"count\":[{\"first\":1,\"second\":2,\"third\":3},{\"first\":11,\"second\":22,\"third\":33},{\"first\":111,\"second\":222,\"third\":333}]}]";
            int oo = 0;
            int[,] jsona = new int[100, 9];
            List<jCount> jsone = JsonConvert.DeserializeObject<List<jCount>>(jsonr);
            foreach (var element in jsone[0].count)
            {
                oo += 1;
                jsona[oo, 1] = element.first;
                jsona[oo, 2] = element.second;
                jsona[oo, 3] = element.third;
            }
   
Comments
Bryian Tan 4-Apr-17 22:21pm
   
This should work :) +5
Karthik_Mahalingam 4-Apr-17 23:19pm
   
Thank you Bryian Tan :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900