-1

我从两个不同的 Web 服务获得响应数组。但是对于相同的方法。问题是有 2 个不同的 Web 服务给了我不同的响应。这些是那些数组

(NSMutableArray *) $2 = 0x003e9210 <__NSArrayM 0x3e9210>(

{

addedOn = "03/09/2013";

album = "Surendra Perera";

artistGroup = Female;

artists = "Surendra Perera";

bpm = 0;

categories = "Love Songs";

duration = "250.00";

energy = "";

era = Millenium;

extroTime = "0.00";

extroType = "";

genders = "";

id = 50;

imageUrl = "http://sample.com/CloudMusic/Images/sngfile.png";

introTime = "0.00";

language = Sinhala;

lyrics = "";

mediaUrl = "http://sample.com/CloudMusic/Music/0476/50.mp3";

moods = Lonely;

movie = "";

musicLabel = Evoke;

musician = "";

sDuration = "00:04:10";

soundCodes = "";

tempos = "";

textures = "";

thumbUrl = "http://sample.com/CloudMusic/Images/sngfile.png";

title = "Mee Mai Gaha";

writer = "";

year = "";

}

)

另一种是

addedOn = "19/09/2013";

albumName = Massina;

artists =     (

            {

        artistGroup = 0;

        description = "<null>";

        id = 290;

        imageUrl = "<null>";

        name = Daddy;

        noOfSongs = 0;

        thumbUrl = "<null>";

    }

);

duration = "260.00";

id = 2575;

imageUrl = "http://sample.com/CloudMusic/Images/sngfile.png";

mediaUrl = "http://sample.com/CloudMusic/Music/0905/2575.mp3";

sDuration = "00:04:20";

songMoods =     (

            {

        id = 3;

        name = Sad;

        noOfSongs = 0;

    }

);

thumbUrl = "http://sample.com/CloudMusic/Images/sngfile.png";

title = "Aai Kale";

year = "";

}

)

我想做的是检查这个艺术家阵列。我如何检查这些艺术家是否以数组或字符串的形式出现。请帮我。

谢谢

4

2 回答 2

3

这将说明您的问题 Get data rx in _recievedData 然后检查对象的类。

id object = [NSJSONSerialization
                 JSONObjectWithData:_recievedData
                 options:kNilOptions
                 error:&error];
if (error)
{
     NSLog(@"Error in rx data:%@",[error description]);
}
if([object isKindOfClass:[NSString class]] == YES)
{
     NSLog(@"String rx from server");
}
else if ([object isKindOfClass:[NSDictionary class]] == YES)
{
     NSLog(@"Dictionary rx from server");
}
else if ([object isKindOfClass:[NSArray class]] == YES)
{
     NSLog(@"Array rx from server");
}
于 2013-10-10T04:14:25.717 回答
0

这应该可以帮助你。

id object = [responseData objectForKey:@"artists"];

if ([object isMemberOfClass:[NSString class]]) {
    // do the stuff for NSString
}
else if ([object isMemberOfClass:[NSArray class]]) {
    // do the stuff for NSArray
}
于 2013-10-10T04:42:32.647 回答