-1

I've done this thing lots and lots of time. But I don't know why I can't figure out what is the issue with this object when I try to fetch it from NSDictionary.

I've NSMutableArray object which have below data.

( { SelectUserDataResult = "[{ 'UserID': '3D5CC4E6-25E8-4591-A84A-6BD7D020DB17', 'ClientID': '895D7BE5-B5D0-48AE-8AAB-6863FCD1D5BF', 'TimeZoneCulture_Term': 'en-US', 'Currency_Term': 'GBP', 'LoginLogID': 'c76960b1-aa24-454f-9fe7-f4f3960fefd4' }]"; } )

Now I fetch my first object like

NSDictionary *dicResponse = [[[NSDictionary alloc]initWithDictionary:(NSDictionary *)[data objectAtIndex:0]] objectForKey:@"SelectUserDataResult"];
NSLog(@"%@",dicResponse);

[{ 'UserID': '3D5CC4E6-25E8-4591-A84A-6BD7D020DB17', 'ClientID': '895D7BE5-B5D0-48AE-8AAB-6863FCD1D5BF', 'TimeZoneCulture_Term': 'en-US', 'Currency_Term': 'GBP', 'LoginLogID': 'c76960b1-aa24-454f-9fe7-f4f3960fefd4' }]

Now, from above I want fetch UserID and other things so, I just code like

NSString *abc = [dicResponse objectForKey:@"UserID"];

but it gives me error like

-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7a70200

Can't find where I'm wrong.

Thanks

========= Part-2

I just mange to change my NSMutableArray object data as below

( "[{ 'UserID': '3D5CC4E6-25E8-4591-A84A-6BD7D020DB17', 'ClientID': '895D7BE5-B5D0-48AE-8AAB-6863FCD1D5BF', 'TimeZoneCulture_Term': 'en-US', 'Currency_Term': 'GBP', 'LoginLogID': 'c76960b1-aa24-454f-9fe7-f4f3960fefd4' }]" )

NSDictionary *dicResponse = (NSDictionary *)[data objectAtIndex:0];

gives me the same thing as last.

how to remove " as mikeweller suggest.

4

2 に答える 2

3

エラーは、それdicResponseが実際には文字列であることを示しています。

これは、キーに文字列値があることを意味します。値は二重引用符で囲まれているSelectUserDataResultため、投稿したデータで確認できます。SelectUserDataResult

"から周囲を削除するSelectUserDataResultと、コードが機能するはずです。

この文字列を外部ソースから JSON として取得する場合は、次を使用してデコードする必要がありますNSJSONSerialization

于 2013-05-03T08:59:30.523 に答える
0

JSONパーサーを使用して文字列を解析する必要がありますが、文字列は一重引用符で生成されるため、JSONは二重引用符である必要があるため、最初にサーバー側でこれを変更するか、ローカル側ですべての一重引用符を二重引用符に置き換える必要がありますが、それは良い選択ではありません。

解析するには、次のリンクにアクセスしてください

http://json.parser.online.fr

于 2013-05-03T11:26:33.480 に答える