Dealing with JSON data can be tricky, especially when working with multiple sets of information to choose from.
When I inspect the data in my JavaScript code using
console.log(contacts.data["all"]);
, I can see the returned objects clearly.
Here's a sample of what the output looks like:
0: Object
allowanyoneedit: "True"
allowedit: "1"
charindex: "A"
country: "AF"
email: "xx@xx"
Among all the data available, my goal is to extract the email information only.
For instance, if the data includes:
0: Object
allowanyoneedit: "True"
allowedit: "1"
charindex: "A"
country: "AF"
email: "xx@xx"
1: Object
allowanyoneedit: "True"
allowedit: "1"
charindex: "A"
country: "AF"
email: "zz@xx"
and I specifically want to retrieve the 1st object's details from the JSON data, how would I achieve this using JavaScript?
=========================edit=========================This section demonstrates how I am handling and processing the data array:
for (var x in companies) {
var company = companies[x];
var opt = $("<option>").attr({ value: company.id }).text(company.name);
$("#contactcompany").append(opt);
console.log(company);
//$("#txtEmailTo").val();
console.log(contacts.data["all"]);
In the example scenario, there are a total of 5 objects in the array.
========================edit 2==============================Data += "{"
For Each item In Columns.Split(",")
Dim Val As String = FormatJS(myReader(item).ToString)
If Val <> "" Then Data += """" & item.ToLower & """:""" & Val & ""","
Next
If CBool(myReader("AllowEdit").ToString) = True Then
Dim Val As String = FormatJS(myReader("AllowEdit").ToString)
If Val <> "" Then Data += """allowedit"":""" & Val & """"
End If
If Data.EndsWith(",") Then Data = Data.Remove(Data.Length - 1)
Data += "},"