-1

I am working with some json data, and in the results set that i have i have 5 sets of information that i can choose from.

in my javascript i can see the data returned as objects when i call the line console.log(contacts.data["all"]);

a sample of the output is as follows which is from the debugging window from chrome

0: Object allowanyoneedit: "True" allowedit: "1" charindex: "A" country: "AF" email: "xx@xx"

In the data that i have I want to get the email information,

so if i had;

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 wanted to return option the 1: object from the json how would i do this with the Javascript =========================edit=========================

this is the block where i know i am getting the data through to get teh 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 i am working with there are 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 += "},"
Simon Price
  • 3,011
  • 3
  • 34
  • 98

1 Answers1

0

Assuming your JSON is like:-

vat data = {
    0: {
        "allowanyoneedit": true, 
        "allowedit": 1, 
        "charindex": "A", 
        ...
    }, 
    1: {
    ...
    }
}

then i would do:

console.log(data["1"]);

to get the email from 1,

console.log(data["1"]["email"])
Abhinav
  • 89
  • 2