By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. The latest returns idso its a good idea to check the returned object type after you cast here i casted to NSDictionary. Learn more. Ask Question. Asked 9 years ago.

Active 2 years, 7 months ago. Viewed k times. Stanislav Pankevich 8, 6 6 gold badges 51 51 silver badges bronze badges.

Ali Ali 9, 10 10 gold badges 51 51 silver badges 82 82 bronze badges. Active Oldest Votes. KIDdAe 2, 2 2 gold badges 19 19 silver badges 28 28 bronze badges. Anh Nguyen Anh Nguyen 5, 1 1 gold badge 17 17 silver badges 18 18 bronze badges. Brian 9, 7 7 gold badges 31 31 silver badges 43 43 bronze badges. LeonS LeonS 2, 2 2 gold badges 27 27 silver badges 36 36 bronze badges. Aleksandr B. Luca Davanzo Luca Davanzo Did not work!

Swift 3 equivalent code did not work.Tag: objective-cjsonnsjsonserialization. That is why the back slash is added in your result. You can refer hereto know why doing so.

convert nsdictionary to nsdata

If you convert the string back to JSON object and logged the object, you can see the result as expected. Thus you can verify, there is nothing wrong with the string. Roll back those changes, add a InfoPlist. So you never get the value. The first one mutates the existing NSMutableString. Adds to the end of the receiver the characters of a given string.

The second one returns a new NSString which is a concatenation of the receiver and the parameter. Returns a new string made Here's what I would do.

Subscribe to RSS

You just need to POST data to your server. Port could be anything you want, should be Host your script with a domain url so that you can make network request publicly. What the show e. Push segue does internally is to call -[UIViewController showViewController:sender:] Calling this method on your view controller itself, will trigger the appropriate way of presenting the view controller you are passing.

Here you're setting the delegate of a controller you just instantiate and not the one which poped the controller. If you look at the method you have defined in Objective C image category, it is instance method and you are trying to call it using UIImage class in swift. You can basically use either one of the following two approaches, Either, self.

Based on the comments on the question, you mentioned that the words will never change. I have put this down as a more efficient alternative and it should hopefully work You only need to make sure you also return the promise in your nb1, nb2, nb3 functions. You're binding the container object, not the list itself.

Change it to: GridView1. PersonDetails; And it should work I guess the answer depends on your answer to these questions: Since you can never trust ANYTHING that comes in a client request, are there any harmful effects that could come by a hacker spoofing the pojo value? By sending the object to the client, does this expose any internal If you need to match [ and ] you can use matches operator, which uses regular expressions.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I am not sure if I am using the dictionary or the data object or both incorrectly. I m trying to get used to the switch to swift but I'm having a little trouble. Leo's answer gave me build time errors because NSData isn't the same as Data. How are we doing?

Convert the JSON data to an NSDictionary

Please help us improve Stack Overflow. Take our short survey. Learn more. Asked 5 years, 5 months ago. Active 1 year, 11 months ago. Viewed 74k times. Any help is greatly appreciated, thanks. Stanislav Pankevich 8, 6 6 gold badges 51 51 silver badges bronze badges.

IanTimmis IanTimmis 1 1 gold badge 5 5 silver badges 14 14 bronze badges. What are you actually trying to achieve? Active Oldest Votes. NSDictionary Swift3. Castor 2 2 gold badges 6 6 silver badges 23 23 bronze badges. Leo Leo You did answer my question specifed in the title. I think AnyObject was wrong. Am I able to do that? This is from the doc of xocde. Nevermind when i end up using them i just say data.

This doesn't work. I answered the answer when it is swift 1. So,for swift 2. NSPropertyListSerialization may be an alternative solution. Immutable, format: nil as! Nikolaj Nielsen 1, 1 1 gold badge 11 11 silver badges 28 28 bronze badges.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

I'm using an API service of a web service and it is written in their description that they send JSON data wich also matches in my opinion with the response I get from it. In the NSLog-String it stops there. Everything indicates that the JSON packet is incomplete but I don't know how to check it or how to look for the issue which should be located in my code.

If so you may get incomplete data and that can not be converted.

How can I convert NSDictionary to NSData and vice versa?

Learn more. Asked 5 years, 11 months ago. Active 5 years, 11 months ago. Viewed 24k times. Cocoa error There is nothing you can do. You can't convert it because its incomplete. Yes MartinH you are right and I did it like Rajeev wrote in his answered too!

Thank you very much! Active Oldest Votes. Hope it will help. Rajeev Rajeev 3 3 silver badges 13 13 bronze badges. Thank you SO much! You was right it was just a part of the response I received and I forgot to use the other delegates and append all data to the finally JSON! I am so happy haha - great work! Sign up or log in Sign up using Google.

convert nsdictionary to nsdata

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Socializing with co-workers while social distancing. Podcast Programming tutorials can be a real drag. Featured on Meta. Community and Moderator guidelines for escalating issues via new response….Skip to content. Instantly share code, notes, and snippets. Code Revisions 1 Stars 4. Embed What would you like to do? Embed Embed this gist in your website. Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. The description for the dataFromPropertyList class method seems confusing if you don't understand that you can create a property list with no keys: that is, you can create one with a single compliant object, and the key becomes "root".

This comment has been minimized. Sign in to view. Copy link Quote reply. Originally posted in on my iWeb site iWeb is going away soon.

SwiftUI Tutorial - How to Customise a Navigation Bar using Xcode 11.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. So, in the unlikely event that some else someday has the same mental block, here is actual tested code that takes a NSDictionary and creates a binary plist file:. NSLog "Create failed". Just to prove to myself that yes, you can create a property list with other objects like NSNumbers or raw NSData, I added these two tests:.

Here is the above code wrapped in a short command line test program:. NSLog "cannot create output stream". Hope this is of use to someone else.Hello everyone. I'm having issues trying to find out how to work with custom data being sent from the Apple Notification Service. My app is subscribed to receive push notifications from APNs. I am successfully subscribed and I can send notifications to my app through APNs. They show up on my device as they should. I wanted to send custom data to the app when I send a notification.

The custom data is outside of the 'aps' JSON class as it should be and it comes through to the app. In the app, I have a custom delegate that I attach to the iOS user notification center.

convert nsdictionary to nsdata

This allows the overrides WillPresentNotification method in my delegate to fire. Here is the structure of that method The problem is that when I receive the data, it doesn't come back as properly formatted JSON that I am clearly sending from the server side. When I look at the custom data that comes back in the notification. It's the same process that I am using to build the aps class for the notification itself. I can see the data is properly formatted before I submit it to APNs. The data is coming from custom classes in my library.

The ultimate goal is to translate the custom data received from APNs back into my custom class within the app. Maybe I'm not extracting the data in the proper way or from the proper area? Maybe what I am looking at is just raw data when I call ToString. Thank you in advance. And what do you get in the WillPresentNotification event? My sending payload is properly formatted JSON as per the spec. When I extract the data using notification. ToString and print to the immediate window in visual studio, i get the following As you can see, we send JSON format and get junk back.

I'm still not sure why they want us to send JSON format, but insist on sending us back unformatted junk. I just have this feeling that. ToString is not the property I want to be trying to extract the data I need. I just can't find the property I need to get my data custom class back from and how to convert it.

You can consume it directly like:. Thank you LandLu. It would have been much easier if they would have left it as-is in JSON, because we could have converted it to our own custom classes easily with only two lines of code. Does this mean I need to build my own converter to convert them back to my own custom classes then? I saw another post on this forum where someone created a generic converter for the primitive types to.

NET types. That could be used in a loop against the reflected type to do the work if I had to.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Is it possible? The reason I am doing this, Is I need to check the content of a NSDicitonary without the debugger running on my device. Above Solutions will only convert dictionary into string but you can't convert back that string to dictionary. For that it is the better way.

Learn more. Asked 8 years ago. Active 4 years, 8 months ago. Viewed k times. Johns C. Johns 9, 18 18 gold badges 97 97 silver badges bronze badges. Similar question: stackoverflow. Active Oldest Votes. Jay Wardell Jay Wardell 2, 1 1 gold badge 11 11 silver badges 11 11 bronze badges. Johns Apr 12 '12 at Can we just do [myDictionary description] to get the dictionary in string format?? Danial Hussain Danial Hussain 2, 14 14 silver badges 31 31 bronze badges.

It worked for single dictionary. What in case of multiple dictionaries? I am unable to convert back to dictionary. VineetAshtekar see the title of this question. DanialHussain Yeah i know that.

There can be arrays as values in dictionary right? So when it does, this method was not working. Sign up or log in Sign up using Google.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *