我认为最合适的解决方案是正确格式化JSON对象上的数字,即不要将其用引号引起来。所以:
[{"id":"42","firstname":"Sarah","lastname":"Dilby","age":"40","cars":"Yaris"}, {"firstname":"Jason","lastname":"Diry","age":"5","id":"5"}, {"id":"6","firstname":"Bilson","lastname":"Berby","age":"1","cars":"Tipo"}]
变成:
[{"id":42,"firstname":"Sarah","lastname":"Dilby","age":40,"cars":"Yaris"}, {"firstname":"Jason","lastname":"Diry","age":5,"id":5}, {"id":6,"firstname":"Bilson","lastname":"Berby","age":1,"cars":"Tipo"}]
我猜想SergL的解决方案是好的,如果不可能更正JSON数据的格式。
除此之外,在我的特定情况下,问题与服务器端PHP的json_enpre函数有关。默认情况下,它将数字视为字符串。要修复,我必须
JSON_NUMERIC_CHECK在PHP脚本中将选项添加到enpre方法:
json_enpre($assoc_array,JSON_NUMERIC_CHECK);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)