Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to parse a json string in my code , how ever I am getting an error as below.
SyntaxError: Unexpected token i in JSON at position 2.
here is my code that tries to parse the string. this piece of code is written in my angular project .
JSON.parse('{ "id": "id", "lastName": "prasanth", "firstName": "mp", "password": "bingo!!!", "passwordInHistory": "true" }'))
there's one too many parentheses at the end
try this instead:
JSON.parse('{ "id": "id", "lastName": "prasanth", "firstName": "mp", "password": "bingo!!!", "passwordInHistory": "true" }')
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Why doesn't JSON tolerate a trailing comma after the last element?
[
{
"id": 1,
"username": "john"
},
{
"id": 2,
"username": "william"
}
]
Be it a comma after the value "John" or be it the second JSON user object, why is JSON not tolerating the comma? Don't we have a simple engineering solution that can solve this tiny problem and by the way we are in the "Deep Learning" era. I am more curious to know why does it exist.
An array structure is represented as square brackets surrounding
zero or more values (or elements). Elements are separated by
commas.
array = begin-array [ value *( value-separator value ) ] end-array
There is no requirement that the values in an array be of the same
type.
RFC 7159 section 5
Effectivly, trailing commas are not allowed as defined by the specification.
There are linting tools which will automagically fix it for you, but it's usually a sign you've done something wrong.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
[
1618511472,
"on-req",
null,
null,
[
[
62577595747,
]
],
]
Above is the json response that needs to be parsed
I'm currently using var resp []interface{} and json.Unmarshal for the raw response. It works for other fields except the array field
When I try to cast the array field resp[4].([][]interface{}) it doesn't work
Not sure what is the best approach here. Appreciate any help. Thanks beforehand
Thanks to mkopriva's answer
This is the working solution
tmp, ok := resp[4].([]interface{})
tmp1, ok1 := tmp.([]interface{})
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have a Rust library and Ruby project. I call a Rust function from Ruby via FFi.
There's a function in the Rust library that receives a string and converts it into json.
Ruby side:
my_json_raw_str = {
network: {
server_address: "my_server.com"
}
}
res = send_it_to_rust(my_json_raw_str.to_json)
A function in Rust will throw an exception when parsing json string sent to it from Ruby.
An error returned from Rust:
Invalid parameters: trailing characters at line 1 column 47\nparams: [{\"network\":{\"server_address\":\"my_server.com\"}}\u0000]
Json is valid, isn't it?
serde, serde_json and serde_derive are used on Rust side.
How to fix the error and why is it caused?
Json is valid, isn't it?
Your JSON is not valid, because your FFI layer is not correct: if you look at the error it's clearly telling you that there is a trailing NUL byte in your data, meaning when bridging between C and Rust you left the trailing NUL byte from the C string.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
After calling data from API using, dictonary = try JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary. My value is always in parentheses. How do change from parentheses to bracket?
What you're seeing is just an artifact of how Xcode (really lldb) displays dictionaries when debugging.
["{key}":{value}...] will be used to display any dictionary.
({value}...) will be used to display arrays
The rest of what you see is because the coordinates array is an array(1) of array(1) of array(1) of array(2) with two values [[[[Double]]]]
Mostly you just need to learn to read the debugger output.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have response from server in this format :
{
"id":"552cd25444ae47fe5f3a41b2",
"eventType":"REST_EVENT",
"userSid":"REST_USER",
"content":{
"key":"value",
"key1":"value1",
"key2":"value2"
}
}
How I can map content field to Ember Data Model if this field has dynamic count of values and without knowing key names ?
Its really simple. Use this in your model
content : DS.attr()
Ember will automatically pick up if you pass array, string or number. In your case array.
You can even iterate over it. Watch it using Observers like any other array or model attribute in Ember.