javascript - jQuery.parseJSON disordered array -
Code> Array ([979] = & gt; Picture model [962] => Brand [4 9 4] => Dimension [980] => Capability [981] => Power [982] = & Gt; List Price [983] = & gt; Warranty [975] => USB Connection [9 76] => Self-cleaning [9 77] => Double Glass Door [978] = & gt; Steam Function [974] => Electrical type)
In your code given below, comparable_at contains a Jason encoded array After this, I give a json in the order of php array as console.log (comparable_attr) . Then, after parseJSON and then console.log gave it the data in different order. Problem: I want to get it after parseJSON in the same order. Received result: returns the first Console.log (comparable_ETR): returns the second Console.log (obj): Edit : Everything I found is small according to my attribute ID, which I need in the same order Because it's in the array. When you change a JS spray array to JSON and later in the JS variable you will get a JS < Code> object , not an array, and the JS object is clearly a set of an unmarried key value pair. If you want to preserve the order you will first need to rearrange the data on the PHP side, perhaps: Note that if you do this, The ability to view data will lose, as the resulting JS object will look: Alternatively, it may be possible to send its existing array, but also sends a second array which is the only sort of keys that can be used prior to key-based lookup, later on To determine the correct order:
var comparable_attr = '& lt ;? Php echo json_encode ($ _ comparable_attributes); ? & Gt; '; If (comparable_art.line! = 0) {// check for Jason Console.log (comparable_ETR); Var obj = jQuery.parseJSON (comparable_ETR); Console.log (obj); }
"979": "Picture model", "962": "Brand", "9 4": "Dimension", "980": "Capacity", "981": "Power", "982": " "987": "Warranty", "975": "USB connection" 976 ":" self cleaning "," 977 ":" double glass door "," 978 ":" steam function "," 974 " : "Electricity Type"}
object {494 = "dimension ", 962 =" brand ", 974 =" electric type ", and .. ..}
Array ([979] = Array (Picture Model), Array ([962] = & gt; Brand), ...)
[["979": "Picture model"}, // NB: All JS keys are string {"962: "Brand"}, ...]
json_encode (array ('data' = & gt; $ _comparable_attributes, 'order' = & gt; array_keys $ _comparable_attributes)); < / Pre>
Comments
Post a Comment