Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

objective c - NSMutableDictionary is adding quotes to keys and values - why?

I'm trying to add some additional key/value pairs to an NSMutableDictionary, using:

Tag *tag1 = [results1 objectAtIndex:0];
[resultsDict setObject:[tag1 retrieveTextUpToDepth:1] forKey:@"image_url"];

Tag *tag2 = [results2 objectAtIndex:0]; 
[resultsDict setValue:[tag2 retrieveTextUpToDepth:1] forKey:@"majority"];

This adds the k/v pairs with no problem, except when I come to retrieve them, some of the values have been wrapped with double quotes:

po extendedDataDictionary:

    "image_url" = "/images/mpsL/11727.jpeg";
    majority = 3460;

Both keys and values are NSStrings, with no quotes - so I'm stumped as to where they're appearing from.

Is there any way of preventing this?

Or am I going to have to live with it and try to strip off the quotes once I've retrieved the value?

Thanks...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The quotes aren't really part of the content; the -description method (called by po, IIRC) simply wraps things in quotes for display that have non-alphanumeric characters in them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...