AFNetworking JSON text did not start with array or object and option to allow fragments not set - objective-c

I am getting response for my web-service like this when I run it in browser: IN.Tags.Share.handleCount({"count":5,"fCnt":"5","fCntPlusOne":"6","url":"http:\\myWebService?postid=24"});
But when I use afnetworking code to get response it gives error like:
Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set.
how can I get response like only :
({"count":5,"fCnt":"5","fCntPlusOne":"6","url":"http:\\myWebService?postid=24"})

Related

can not send int to respond in ktor

I'm trying to send int response but get an error but when I use both as a string then response get successfully.
post("/employee") {
call.respond(mapOf("hey" to "Hey","if" to 1))
}
LOGCAT
java.lang.IllegalStateException: Serializing collections of different element types is not yet supported. Selected serializers: [kotlin.String, kotlin.Int]
at io.ktor.serialization.kotlinx.SerializerLookupKt.elementSerializer(SerializerLookup.kt:45)
at io.ktor.serialization.kotlinx.SerializerLookupKt.guessSerializer(SerializerLookup.kt:29)
at io.ktor.serialization.kotlinx.KotlinxSerializationBase.serialize$ktor_serialization_kotlinx(KotlinxSerializationBase.kt:34)
at
You can't pass different types in response "yet" like mentioned in stacktrace. As a workaround you can pass 1 as string or create custom class for this response and serialize it to json and send it like that

microsoft graph api - error responses returning as plain text

I'm using the the graph api in an internal .Net Core 3.1 webapi. However, each time a failed response is returned, it returns as a 500 internal error with the response as content-type: text/plain.
Status Code: NotFound
Microsoft.Graph.ServiceException: Code: Request_ResourceNotFound
Message: Resource '********' does not exist or one of its queried reference-property objects are not present.
Inner error:
AdditionalData:
date: 2020-10-13T13:44:21
request-id: 8053255b-2f1c-4543-8de7-*******
client-request-id: 8053255b-2f1c-4543-8de7-*******
ClientRequestId: 8053255b-2f1c-4543-8de7-*******
I am looking for the response to be return in JSON format similarly to the MS Graph Api explorer with the appropriate error code instead of a 500 Internal Error.
I believe the error you're looking for is inside
Microsoft.Graph.ServiceException -> Error -> Code.
If you'd like it in Json format you could convert it using JsonConverter.

Invalid request body error when sending json string as data to an external api using CL_HTTP_CLIENT

We are facing an issue while sending json data to an external api using CL_HTTP_CLIENT.
The JSON data is produced using '/ui2/cl_json=>serialize( data = ls_body compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case )' .
when sending this JSON as data the the external api returns status 400 with response as
{ "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted. Unexpected character encountered while parsing value: \u001f. Path '', line 0, position 0." } .
we also stringyfied this JSON Data in backend as it might be due to parsing error but it didnt work.
The same stringyfied data tried to send through browser console using ajax and it did worked without any issue.
could any any one tell us how to handle this json object and send this to external api using CL_HTTP_CLIENT.
Note : JSON STRING is deeply nested .
Thanks in advance..
You can use request catcher service for getting SAP output.
Then check your output has valid json.
Check external api with rest tool like postman or SoapUI. Every developer not track guidliness may be external api has limitations.
The issue was with the unicodes in the string.
these were not accepted by the external api so removed from the string and sent to api and it did worked.
Thanks for You suggestion.

json parsing using GET method

I just want to hit URL :http://kiascenehai.pk/rest_api/todayEvents/api-key/Of7NU7Jimh665D5G5VwO2eKO69sWv9lf/format/json
and parameter is city_id.i.e: /city_id/1
but; compiler creates Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" or error 300; so what shall be best way to pass arguments ?

WCF error handler

I have created a web service based on
http://blogs.msdn.com/b/endpoint/archive/2010/01/06/introducing-wcf-webhttp-services-in-net-4.aspx
i am trying to add an error hadler based on
http://www.codeproject.com/KB/WCF/WCFErrorHandling.aspx
I have given
In web.config such that i am getting
result of a [OperationContract]
either as xml or as Json based on the request content type header.
But when an error occurs the error is returned only as XML
It is not returning error as JSON
Wat can i do to get error as JSON?
You need to implement IErrorHandler and write a ProvideFault method to output as WebContentFormat.Json
you can get all the details of how to do it here:
http://blog.manglar.com/how-to-provide-custom-json-exceptions-from-as-wcf-service/
http://blog.wadolabs.com/2009/03/wcf-exception-handling-with-ierrorhandler/