-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String parsing #9
Comments
Interesting use case! Why do you expect to achieve from this input, a dictionary, right? |
Interesting |
I was just using it to play around with in a Playground to see how JSONValue's worked. From the source it looked like JSONValue() took String input so I tried it out. Haha, now after reading your reply I get that JSONValue's hold individual element data and that it wasn't meant to parse string input. Ya, that was confusing to me, i'd recommend making a separate init that only takes NSData or allowing String input as well. |
I've thought about implementing literalConvertibles, but It's not the case where it will help. If we implement convertible, the call will look like: |
Maybe, it will be better to make the following public api:
This will allow us to keep these two use cases separated |
Agreed! :) |
As addition to previous comment: I personally do not like .JInvalid as return value. For me, it looks more natural to return here something like fancy optional wrapper: http://swiftlytyping.tumblr.com/post/88210131086/error-handling |
@lingoer it will be really pain to implement, regexp all the things? I still do not see any real-world usage for this |
An ugly implementation would be String => NSData => NSJSONSerialization, ugly, but worked?
|
I like |
Ok, I'll commit the JInvalid thing later and think awhile for the init method. I want to keep NSData as the default init ,while provide some other init method for other types |
Could someone give a example how to parse these JSON strings ? Received_JSON_string: {"a":"actionvalue"} let json = JSON(Received_JSON_string) |
let json: JSON = JSON(data: Received_JSON_string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!)
let action = json["a"].stringValue
println("Received a: \(action)") |
@lobodart Works ! |
Cool library!
Having trouble getting the right output from string input:
The text was updated successfully, but these errors were encountered: