JSON text did not start with array or object - ios

Working with an iOS app managing data on a Parse-Server (/Heroku).
I have the following issue when trying to save data.
Here is the code for the function where the problem happens:
func saveDataBlockOnline(_ dico: [String:String]) {
let psvClassName = "Goodies",
dataUnit=PFObject(className: psvClassName,
dictionary: dico)
dataUnit.saveInBackground {
(succeeded:Bool, error:Error?) in
if succeeded {
// Do something useful.
} else {print("\(#function) Error:\(error ?? "" as! Error)")}
}
}
Here is the error I get:
saveDataBlockOnline Error:Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
I guess I am getting some JSON answer that I don't use properly. So how should I modify the code?
There are other posts on the subject, but nothing that I found with a real solution.
A few more details may be useful:
The data saving on the server itself was working. But things started to go wrong when I added some cloud code, namely a Parse.Cloud.beforeSave to have a better control on how things are happening.

The data you want to parse in not in correct format according to error message. Check your dictionary and Object(dataUnit) format

Related

Storing a PKDrawing object to Core Data

I am trying to add Apple Pencil support to my mind mapping app. I already use Core Data within my app for data persistence which all works fine without any bugs.
I have my Apple Pencil features working fine but I'm having trouble storing the Apple Pencil data.
Ive tried to add a PKDrawing object to my MindMap data model but I keep getting a compile time error 'cannot find type 'PKDrawing' in scope'
As far as I am away I can store the PKDrawing object into core data and then fetch it back out when the app loads. But I'm obviously not doing something right.
Any help is greatly appreciated folks.
Thank you
Update:
So I've used:
func convertToData(pkdrawing: PKDrawing) -> Data {
let data = pkdrawing.dataRepresentation()
return data
}
Then updated my model data and savedContext which all seems to work ok. The problem is when I try and initialise the data on opening the app. I have:
func createDrawing(data: Data) -> PKDrawing {
var loadedDrawing: PKDrawing
do {
try loadedDrawing = PKDrawing.init(from: data as! Decoder)
return loadedDrawing
} catch {
print("Error loading drawing object")
return PKDrawing()
}
}
which gives me error:
Could not cast value of type 'Foundation.Data' (0x1f3851a98) to 'Swift.Decoder' (0x1ee5381a8).
2021-09-24 06:22:58.912173+0100 MindMappingApp[1137:612856] Could not cast value of type 'Foundation.Data' (0x1f3851a98) to 'Swift.Decoder' (0x1ee5381a8).
I tried:
try loadedDrawing = PKDrawing.init(from: data as! Decoder)
as:
try loadedDrawing = PKDrawing.init(from: data)
but I kept getting:
Argument type 'Data' does not conform to expected type 'Decoder'
any ideas? Thanks in advance :)
Instead of trying to store the PKDrawing directly, store the Data associated with it instead.
Your Core Data model will have a field with the type Data (or Binary Data if you're using the GUI).
When you need to actually use that data and covert to/from the PKDrawing, you can use:
init(data:) https://developer.apple.com/documentation/pencilkit/pkdrawing/3281882-init
dataRepresentation() https://developer.apple.com/documentation/pencilkit/pkdrawing/3281878-datarepresentation

Implement MCOHTMLRendererIMAPDelegate in MailCore2 using Swift

Recently I've been trying to use MailCore2 inside my react-native app to read mails, so I made a RCTBridge in Swift for it, and I want to return a simple html string of fetched messages... I have successfully fetched messages of type [MCOIMAPMessage] and now I want to map over this array to convert it to html string with the following code
let msgs = (ret.value(forKey: "messages") as! [MCOIMAPMessage]).map{
[
"html": $0.htmlRendering(withFolder: folder as String,
delegate: MCOHTMLRendererIMAPDelegate()) as NSString,
] as NSDictionary
}
Obviously it gives an error, can somebody please tell me the right way to do it...? Or at least tell me how to implement a MCOHTMLRendererIMAPDelegate

Firebase Crashlytics Custom Log Only Log Single Line

Recently my app has been crashing while trying to deserialize the JSON sent from the server and unfortunately the server doesn't record any log so I can't verify with them. So I decided to log the JSON response for this particular Api, I know that it's a bad practice to log server response but it's the only way I could try to identify the issue, the response for this api is not that long so I think it should be fine.
The issue comes in when I tried to reveal the log and found out it only shows one line in the firebase console as below:
raw response : {
The result I was expecting were something as below,vit shows up nicely in the debug console while developing using CLSNSLogv. I thought it will be the same in firebase console too but it was not the case.
raw response : {
success ={
Status = OK;
Object1 = "test"
Object2 = "test2"
};
}
Below is the code for logging, "value" is a dictionary as below:
value: [String : AnyObject]?
CLSLogv("raw response : %#", getVaList([value!]))
Appreciate your help
This is a Crashlytics issue, my team has been experiencing this issue lately. We were printing dictionary using CLS_LOG in ObjC and we've noticed that it displays only first line of the dictionary.
I've contacted Crashlytics support team, and a guy from there confirmed a bug and told me that he contacted their engineering team for a fix.
You can change the way of logging for now to display everything in single line, or log by log, or you can wait for a fix.
You can convert the response to JSON using JSONSerialization and then remove all the carriage returns so that it's all one line. If you log that modified value it should appear correctly in the Crashlytics logs.

IOS JSON parsing

I am an iOS beginner. I want to test open source application UBER prototype . When I have launched successfully the application on my Mac I have got the problem (signing up for this ) . I guess there is a problem with data base settings .
Error :
Failed to run command eventually with error: Error
Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with
array or object and option to allow fragments not set."
UserInfo={NSDebugDescription=JSON text did not start with array or
object and option to allow fragments not set.}
Could you give me advice how to fix it? The link for the project is here.
I think you have to set option value to NSJSONReadingAllowFragments. Maybe you have set something else!
Try to look something similar like this in your code:
id json = [NSJSONSerialization JSONObjectWithData:contentOfLocalFile options:NSJSONReadingAllowFragments error:&deserializingError];
And please update the question with the JSON format you are getting?

When I am update any field in parse database, I'm getting following error from parse database

Updating any field in parse database I'm getting below error very randomly,
My configuration in the AppDelegate looks like:
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
configuration.applicationId = #"wrWJqA47ZvZA27X26HsJzDxc5xxxxxxx";
configuration.clientKey = #"hOhqpoIVK17joL6GiBGD54XIxxxxxx";
configuration.server = #"https://parse.nightlifexp.com/parse";
}]];
You can see my code for updating parse database in the following link:-https://dpaste.de/Fhrk
The interesting thing is Parse.Cloud.beforeSave function works as expected.Only when I requested data back, this issue appears very randomly.
Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
No proper solution found for this parse database error.Anyone can help me how to solve this problem?
Thanks in advance.
The problem is that your JSON is not an array it has nothing to do with your Objective-c code , but the input from your server is wrong.
I think your solution should be on parse.com .

Resources