运算符'< ='不能应用于'int'和'object []'类型的操作数 [英] Operator '<=' cannot be applied to operands of type 'int' and 'object[]'

查看:94
本文介绍了运算符'< ='不能应用于'int'和'object []'类型的操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经编写了一个代码来显示c#中的JSON数据。这里我有一个对象列表,我想显示它但显示错误:运算符'< ='不能应用于'int'和'object []'类型的操作数。



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[]'.

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!

推荐答案

就像你的错误suegested一样,你无法将 int 数组进行比较对象。

所以你应该像这样改变:

for(int i = 0; i< = obj.Length; i ++){...}
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++){...}


dynamic obj = serializer.Deserialize(e.Result,typeof(object));

int j = 0;

dynamic objects = obj [j];

for(var i = 0; i< = obj.Length; i ++ )

{....

}
dynamic obj = serializer.Deserialize(e.Result, typeof(object));
int j = 0;
dynamic objects = obj[j];
for (var i = 0; i <=obj.Length; i++)
{....
}


这篇关于运算符'&lt; ='不能应用于'int'和'object []'类型的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆