null Value problem solve in the builder sudoku project
First Method I Used ::
json .toString()
Response :: After this I get Error
Second Method I Used ::
{"data":
[
[
[2, null, 5], [null, null, 9], [null, null, 4]
],
[
[null, null, null], [null, null, null], [3, null, 7]
],
[
[7, null, null], [8, 5, 6], [null, 1, null]
],
[
[4, 5, null],[ 7, null, null], [null, null, null]
],
[
[null, null, 9], [null, null, null], [1, null, null]
],
[
[null, null, null], [null, null, 2], [null, 8, 5]]
],
[
[null, 2, null], [4, 1, 8], [null, null, 6]
],
[
[6, null, 8], [null, null, null], [null, null, null]
],
[
[1, null, null], [2, null, null], [7, null, 8]
]
]
}
Response :: After this I get Error
Third Method I Used ::
{"data":
[
[2, "null", 5, "null", "null", 9, "null", "null", 4],
[ "null", "null", "null", "null", "null", "null", 3, "null", 7],
[7, "null", "null", 8, 5, 6, "null", 1, "null"],
[4, 5, "null", 7, "null", "null", "null", "null", "null"],
[ "null", "null", 9, "null", "null", "null", 1, "null", "null"],
[ "null", "null", "null", "null", "null", 2, "null", 8, 5],
[ "null", 2, "null", 4, 1, 8, "null", "null", 6],
[6, "null", 8, "null", "null", "null", "null", "null", "null"],
[1, "null", "null", 2, "null", "null", 7, "null", 8]
]
}
Response :: After this I get the same Output as the Input
Different Types of giving inputs
use json structure instead of array
replace
ids: [null, 1, 2, null, 3]
with
ids: {"0": null, "1": 1, "2": 2, "3": null, "4": 3}
And in controller access it like
params[:ids].values
[nil, 1, 2, nil, 3]In different environment null value is interpreted differently.
I think that the best practice is to replace these entries according the result you want to achieve:
ids.map! { |id| id == null ? nullValue : id }.flatten!
Where nullValue is what you're expecting to have in the array.
Comments
Post a Comment