I am new to JSON and Javasript.
I have data in JSON
var data = [
"FirstName: 'xyz', Lastname 'QSD', rollNo:'1',EntryDate:'2012-09-11T17:35:31.835+02:00'"
"FirstName: 'abc', Lastname 'qgr', rollNo:'2',EntryDate:'2012-08-11T17:35:31.835+02:00'"
]
I want to sort it according to FirstName ,or by roll no or any other attribute i choose.
Thanks in advance.
The first problem is the structure of your data. You have effectively an array like
and these lines of strings contain serialized data. So first we need to extract the data via any method given in this SO question, for example the JSON library method:
Now we have structures like this:
So we can access the firstname via
interpreted[i].Firstname. Now we can sort in a similar way to this other SO question, by passingsort()a comparison function:Where you need to swap 1 and -1 if you want to sort descending.