Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I have did a code to show the JSON data in c#. Here I have a list of object and I want to show it but it showing an error : Operator '<=' cannot be applied to operands of type 'int' and 'object[]'.

C#
try
            {
                var serializer = new JavaScriptSerializer();
                serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
                dynamic obj = serializer.Deserialize(e.Result, typeof(object));
               //int inputNumber = Int32.Parse(obj);
                for (dynamic i = 0; i <= obj  ; i++)
                {
                    dynamic nobj= obj[i];
                    dynamic nfn = nobj["Formatted Name"];
System.Windows.Forms.Label labelInput = new System.Windows.Forms.Label();
                   labelInput.Text = nfn + i;
                    labelInput.Location = new Point(30, labelInput.Bottom + (i * 30));
                    labelInput.AutoSize = true;

                    this.Controls.Add(labelInput);
           }
            catch (Exception ex) { }

If anyone could give me a hand it would be greatly appreciated! Thanks!
Posted
Updated 31-Mar-14 21:41pm
v2

Like your error suegested you cannot compare int with an array of objects.
So you should change your for like this:
for (int i = 0; i <= obj.Length; i++){...}
 
Share this answer
 
Comments
Priyanka Bhawsar 1-Apr-14 5:08am    
Thank you so much, its working.I also found another solution.
Raul Iloc 1-Apr-14 7:34am    
1.Welcome, and if my solution helped you you should accept it!
2.My advice for your is that you should not use dynamic objects when is not necessary, otherwise your code will not be so clear!
dynamic obj = serializer.Deserialize(e.Result, typeof(object));
int j = 0;
dynamic objects = obj[j];
for (var i = 0; i <=obj.Length; i++)
{....
}
 
Share this answer
 

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