简体   繁体   English

如何在Objective-C中增加Json对象

[英]How to increment a Json Object in objective-c

how to increment an Array of Json? 如何增加一个Json数组?

I have this array, this "jsonObjects" loads a Json from webservice: 我有这个数组,这个“ jsonObjects”从webservice加载了一个Json:

            arrBusca = [jsonObjects objectForKey:key];

If I print this array, results this: 如果我打印此数组,则结果如下:

2013-03-26 16:50:48.167 teste[6645:907] array 1: (
    {
    idMarca = 118;
    idTipo = 1;
    marca = "";
    ordem = 9999;
    tipo = Carro;
    },
    {
    idMarca = 60;
    idTipo = 1;
    marca = " -";
    ordem = 2;
    tipo = Carro;
    },
    {
    idMarca = 117;
    idTipo = 1;
    marca = "---";
    ordem = 2;
    tipo = Carro;
   }
}

And I want to increment this array, so I try: 我想增加这个数组,所以我尝试:

    marcas *myPerson = [[marcas alloc] init];
    myPerson.marca = [NSString stringWithFormat:@"Fiat %d", i];
    myPerson.idMarca = [NSString stringWithFormat:@"%d", i];
    [arrBusca addObject:myPerson];

But the result is: 但是结果是:

2013-03-26 16:50:48.167 teste[6645:907] array 1: (
    {
    idMarca = 118;
    idTipo = 1;
    marca = "";
    ordem = 9999;
    tipo = Carro;
    },
    {
    idMarca = 60;
    idTipo = 1;
    marca = " -";
    ordem = 2;
    tipo = Carro;
    },
    {
    idMarca = 117;
    idTipo = 1;
    marca = "---";
    ordem = 2;
    tipo = Carro;
   },
"<marcas: 0x1fd807e0>",
"<marcas: 0x1fd89e40>",
"<marcas: 0x1fd80c90>",
"<marcas: 0x1fd8a1b0>",
"<marcas: 0x1fd8ada0>",
"<marcas: 0x1fd89cb0>",
}

Anyone knows how to increment an jsonobject array? 有谁知道如何增加一个jsonobject数组?

You need to provide NSCoder methods to archive and unarchive your " marcas " objects. 您需要提供NSCoder方法来存档和取消存档“ marcas ”对象。

Right now, when you add the objects to your " arrBusca " NSMutableArray (it is mutable, right?), they're being added as " marcas " objects and not the raw non-marcas objects you decoded from JSON). 现在,当您将对象添加到“ arrBusca ” NSMutableArray(它可变的,对吗?)时,它们将被添加为“ marcas ”对象,而不是您从JSON解码的原始非marcas对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM