Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / April 2007



Tip: Looking for answers? Try searching our database.

Convert NSDictionary to NSData

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lorenzo - 28 Apr 2007 20:31 GMT
The only reference I could find on this was here:
http://lists.apple.com/archives/Cocoa-dev/2003/Aug/msg01381.html

But when I do this, it crashes. I have an NSDictionary only containing
CFStrings. This should work, correct? The docs say objects conforming to
NSCoding protocol will work. Toll-free bridging should apply here
correct? Or do I have to explicitly convert each item to an NSString?
results = [self getResults];
NSData* xmlData = [NSArchiver archivedDataWithRootObject:results];

This is xml data I'm trying to archive.
TIA

Signature

"My Break-Dancing days are over, but there's always the Funky Chicken"
--The Full Monty

Gregory Weston - 28 Apr 2007 22:41 GMT
In article
<lorenzo-1D750B.14311928042007@hedley.internal.thethurmans.com>,

> The only reference I could find on this was here:
> http://lists.apple.com/archives/Cocoa-dev/2003/Aug/msg01381.html
[quoted text clipped - 8 lines]
> This is xml data I'm trying to archive.
> TIA

What actually error and/or warning messages do you get?

Are you sure you know exactly what's in results.

NSLog(@"%@", results); in between the two lines above might be
informative.
Lorenzo - 29 Apr 2007 01:25 GMT
> In article
> <lorenzo-1D750B.14311928042007@hedley.internal.thethurmans.com>,
[quoted text clipped - 18 lines]
> NSLog(@"%@", results); in between the two lines above might be
> informative.

I get a SIGTRAP error. Here is the description:
Printing description of results:
<CFDictionary 0x31a110 [0xa07bc150]>{type = immutable, count = 7,
capacity = 7, pairs = (
  0 : <CFString 0xa0fe698c [0xa07bc150]>{contents = "/WSDebugOutBody"}
= <CFString 0x180c600 [0xa07bc150]>{contents = "<?xml version="1.0"
encoding="UTF-8"?>

 <SOAP-ENV:Envelope

   xmlns:xsd="http://www.w3.org/2001/XMLSchema"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"

   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"

   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

     <SOAP-ENV:Body>

       <ValidateZip xmlns="http://webservicemart.com/ws/">

         <ZipCode xsi:type="xsd:string">60077</ZipCode>

       </ValidateZip>

     </SOAP-ENV:Body>

   </SOAP-ENV:Envelope>

"}
  1 : <CFString 0xa0fe697c [0xa07bc150]>{contents =
"/WSDebugOutHeaders"} = <CFDictionary 0x310eb0 [0xa07bc150]>{type =
fixed-mutable, count = 4, capacity = 17, pairs = (
  3 : <CFString 0xa0fe7530 [0xa07bc150]>{contents = "Host"} = <CFString
0x3155b0 [0xa07bc150]>{contents = "webservicemart.com"}
  13 : <CFString 0xa0fe7520 [0xa07bc150]>{contents = "User-Agent"} =
<CFString 0x311000 [0xa07bc150]>{contents = "Mac OS X;
WebServicesCore.framework (1.1.0)"}
  14 : <CFString 0xa0fe7550 [0xa07bc150]>{contents = "Content-Type"} =
<CFString 0xa0fe7540 [0xa07bc150]>{contents = "text/xml"}
  21 : <CFString 0x316ca0 [0xa07bc150]>{contents = "Soapaction"} =
http://webservicemart.com/ws/ValidateZip
)}
  2 : <CFString 0xa0fe69ac [0xa07bc150]>{contents = "/WSDebugInBody"} =
<CFString 0x1806000 [0xa07bc150]>{contents = "<?xml version="1.0"
encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ValidateZipRespo
nse xmlns="http://webservicemart.com/ws/"><ValidateZipResult>&lt;result
code="200"&gt;&lt;item zip="60077" state="IL" latitude ="42.03331"
longitude
="-87.75764"/&gt;&lt;/result&gt;</ValidateZipResult></ValidateZipResponse
></soap:Body></soap:Envelope>"}
  3 : <CFString 0xa0fe681c [0xa07bc150]>{contents =
"/kWSHTTPResponseMessage"} = <CFHTTPMessage 0x319da0>{url =
http://webservicemart.com/uszip.asmx; status = HTTP/1.1 200 OK}
  5 : <CFString 0xa0fe685c [0xa07bc150]>{contents = "/Result"} =
<CFDictionary 0x319fb0 [0xa07bc150]>{type = mutable, count = 1, capacity
= 4, pairs = (
  1 : <CFString 0x31a6d0 [0xa07bc150]>{contents = "ValidateZipResult"}
= <CFString 0x319fe0 [0xa07bc150]>{contents = "<result code="200"><item
zip="60077" state="IL" latitude ="42.03331" longitude
="-87.75764"/></result>"}
)}
  9 : <CFString 0xa0fe699c [0xa07bc150]>{contents =
"/WSDebugInHeaders"} = <CFDictionary 0x319dd0 [0xa07bc150]>{type =
fixed-mutable, count = 8, capacity = 17, pairs = (
  0 : <CFString 0xa0f91418 [0xa07bc150]>{contents = "Server"} =
<CFString 0x318950 [0xa07bc150]>{contents = "Microsoft-IIS/6.0"}
  3 : <CFString 0xa0f91358 [0xa07bc150]>{contents = "Cache-Control"} =
<CFString 0x319d80 [0xa07bc150]>{contents = "private, max-age=0"}
  4 : <CFString 0x319b70 [0xa07bc150]>{contents = "X-Aspnet-Version"} =
<CFString 0x3189b0 [0xa07bc150]>{contents = "2.0.50727"}
  5 : <CFString 0xa0f913b8 [0xa07bc150]>{contents = "Date"} = <CFString
0x3189f0 [0xa07bc150]>{contents = "Sun, 29 Apr 2007 00:22:53 GMT"}
  6 : <CFString 0xa0f91388 [0xa07bc150]>{contents = "Content-Length"} =
<CFString 0x3180a0 [0xa07bc150]>{contents = "486"}
  7 : <CFString 0xa0f91368 [0xa07bc150]>{contents = "Connection"} =
<CFString 0x318a20 [0xa07bc150]>{contents = "close"}
  11 : <CFString 0x318970 [0xa07bc150]>{contents = "X-Powered-By"} =
<CFString 0x318990 [0xa07bc150]>{contents = "ASP.NET"}
  14 : <CFString 0xa0f913a8 [0xa07bc150]>{contents = "Content-Type"} =
<CFString 0x318920 [0xa07bc150]>{contents = "text/xml; charset=utf-8"}
)}
  10 : <CFString 0x31a6d0 [0xa07bc150]>{contents = "ValidateZipResult"}
= <CFString 0x319fe0 [0xa07bc150]>{contents = "<result code="200"><item
zip="60077" state="IL" latitude ="42.03331" longitude
="-87.75764"/></result>"}
)}

Signature

"My Break-Dancing days are over, but there's always the Funky Chicken"
--The Full Monty

David Phillip Oster - 29 Apr 2007 06:15 GMT
In article
<lorenzo-1D750B.14311928042007@hedley.internal.thethurmans.com>,

> The only reference I could find on this was here:
> http://lists.apple.com/archives/Cocoa-dev/2003/Aug/msg01381.html
[quoted text clipped - 8 lines]
> This is xml data I'm trying to archive.
> TIA

Consider using NSPropertyListSerialization to do it for you.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.