[removed] array.length returns undefined

后端 未结 5 1151
执念已碎
执念已碎 2020-12-23 19:29

I have a set of data that is being passed on by the PHP\'s json_encode function. I\'m using the jQuery getJSON function to decode it:



        
5条回答
  •  情话喂你
    2020-12-23 19:44

    It looks as though it's not an array but an arbitrary object. If you have control over the PHP serialization, you might be able to change that.

    As raina77ow pointed out, one way to do this in PHP would be by replacing something like this:

    json_encode($something) 
    

    with something like:

    json_encode(array_values($something))
    

    But don't ignore the other answers here about Object.keys. They should also accomplish what you want if you don't have the ability or the desire to change the serialization of your object.

提交回复
热议问题