I am working with JSON and i have data to send in JSON form.I have field "stavka" which should be list of JSON objects,[{},{}...],and i have niz=["{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}", "{"redni_broj":"9","naziv_robe_usluge":"12a","kolicina:55","umanjeno_za_rabat":"12","ukupan_porez2":"2"}"],and so I did "stavka":niz within JSON.stringify function,because niz looked as list of JSON objects..But when I send it,it says
"Can not construct instance of..no String-argument constructor/factory
method to deserialize from String value
('{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina":"123","jedinica_mere":"12","jedinicna_cena":"54","vrednost":"12","procenat_rabata":"1","iznos_rabata":"2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}')
Does someone know why this happens?Shouldn't this be working?I thought it is the same as explicitly doing "stavka":[{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}",{"redni_broj":"9","naziv_robe_usluge":"12a","kolicina:55","umanjeno_za_rabat":"12","ukupan_porez2":"2"}]
Thanks in advance!
there are some syntax error in your code. First, you can't write the array like this
niz = ["{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}", "{"redni_broj":"9","naziv_robe_usluge":"12a","kolicina:55","umanjeno_za_rabat":"12","ukupan_porez2":"2"}"],
maybe you means niz is an array like niz = ['xx', 'xx'], but you just the " not ', "{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}" is not a string, it is wrong way to use like that.
'{"redni_broj":"3","naziv_robe_usluge":"gwe","kolicina:2","umanjeno_za_rabat":"43","ukupan_porez2":"33"}' is right way.
Or you can try to use it like this way
"{\"redni_broj\":\"3\",\"naziv_robe_usluge\":\"gwe\",\"kolicina:2\",\"umanjeno_za_rabat\":\"43\",\"ukupan_porez2\":\"33\"}"
I have this complex JSON Format. I don't know Whether is this valid json format or not because the key i am looking for is not in the first two dictionaries but is there in the third dictionary ? Is this valid json format ? If so , how to do parsing in this scenario ?
As am not allowed to ask new question . I edited my old question.
At the end of the first two if blocks, if you put a return statement, that will stop the program from going to execute the Alamofire block.
I am facing one issue but it occurs randomly any time not always. I am not sure what is the issue.
What I am trying is I have an JSON string and I am converting it to DBObject and then push/insert it to mongo DB. below is the code for same.
Here final_json_str is JSON string which I am reading it from input file and then converting it to DBOject and then inserting it to Mongo DB.
val dbObject: DBObject = JSON.parse(final_json_str).asInstanceOf[DBObject]
But some time I am getting error as CastClassException cannot convert java.lang.String to com.mongodb.DBObject.
Can anyone one help me, Am i doing some thing wrong in this. Please let me know if more details are required.
Thanks a lot in advance
from the signature of JSON.parse
public static Object parse(final String jsonString)
One can see it can actually return any Object. Looking a bit further in the actual code, the parse will choose what method to return with a big switch on the first character of your String.
In the case it matches either ' or " the returned Object will be a String which you try to cast into a DBObject.
I found a tutorial for server implementation in a game on this link:
http://unity-tutorials.blogspot.in/
I implemented the code for my server sending in the following data on the Login Section to my Server:
{"email":"rudi#mrpatch.co", "pass": "mrpatch"}
This server is implementing JSON and is giving the below response :
Receive response: "{\"status\":\"success\",\"data\":[{\"id\":\"1\",\"email\":\"rudi#mrpatch.co\",\"password\":\"mrpatch\",\"first_name\":\"Rudi\",\"last_name\":\"Ullon\",\"birth_date\":\"1981-03-20\",\"status\":\"1\"}]}"
There is a JSON parser script in this project, which returns System.string , this is being used by a parser in my other script LoginService.js
But while I am trying to store this in a Boo.Lang.Hash (hashtable) it gives me error in following code:
var parsed : Boo.Lang.Hash = JSONParse.JSONParse(httpResponse.text);
This is the Error message I am getting:
InvalidCastException: Cannot cast from source type to destination type.
LoginService+$sendLoginData$6+$.MoveNext () (at Assets/Scripts/StartMenu/LoginService.js:61)
I have tried saving it a Boo.Lang.Hash, as String etc. but nothing seems to be working.
if you have json you can do in this way.
var parsed : Boo.Lang.Hash = JSONParse.JSONParse(your json );
Oh boy...
You seem to have quite some conceptual issues with type casting and that's a far too broad topic (joke link). :P
The error message means you can't convert from String to that Hashtable through casting. You need a function to convert it for you or do it yourself.
The JSONParse you mentioned can actually do it:
var jsonData : json = json.fromString(httpResponse.text);
At least now you have jsonData.values which can be easily converted to a Hashtable...
But keep in mind "Hashtables" are obsolete and even the Unity Player will warn you about it. Read more.
you must use the JsonPare.js from source code on the demo.https://docs.google.com/file/d/0B0HipNssJJD-bEh0Wi1XeV9PSlE/edit
I figure this may be an unconventional way of creating a JSON string. But, I really need to just be able to make it right in "Sequel Pro" like this
I want to be able to just edit it right there like that. But when I receive the string on the client end, then try to use as3 JSON.parse function on it, it gets an error..."SyntaxError: Error #1132: Invalid JSON parse input."
private function storyTextCallBack(r:Object):void
{
//storyText is an 'Object'
storyText = JSON.parse(r.text);
}
But this is how my client is actually getting it, and it's what I think is breaking the JSON.parse function.....
[\n\t{\n\t\ttext: "hello this is some json test stuff",\n\t\tduration: "5000"\n\t},\n\t{\n\t\ttext: "this is the second line in that json object thing",\n\t\tduration: "3000"\n\t},\n\t{\n\t\ttext: "this is the third and final line in that json object thing",\n\t\tduration: "8000"\n\t}\n]
anyone have any ideas how I can fix this?
The object names in your JSON need to be inside quotes:
"text":"example text"
You can check if you have a valid JSON object with this parser: http://json.parser.online.fr