如何在objective-c中增加Json对象

时间:2022-07-30 16:58:25

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数组吗?

1 个解决方案

#1


0  

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对象)。

#1


0  

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对象)。