JSON id causes error

Aug 17, 2010 at 8:32 AM

Hi All,

Hopefully someone will be able to shed some light on this really odd issue...

I have two flexboxes, both use the same database, both use the same data, the only difference is that one uses an id number for the JSON id and one uses a contract number.  The id version works, the contract number does not.

Here is the code...

This version works

        foreach (DataRow contract in contractNumbers)
        {
            string code;
            code = Convert.ToString(contract["Code"]);
            if (code.IndexOf(query, StringComparison.CurrentCultureIgnoreCase) != -1)
            {
                results.Add("{\"id\":" + contract["ID"] + ",\"name\":\"" + contract["Code"] + " - " + contract["Description"] + "\"}");
                total++;
            }
        } 



This version does not

        foreach (DataRow contract in contractNumbers)
        {
            string code;
            code = Convert.ToString(contract["Code"]);
            if (code.IndexOf(query, StringComparison.CurrentCultureIgnoreCase) != -1)
            {
                results.Add("{\"id\":" + contract["Code"] + ",\"name\":\"" + contract["Code"] + " - " + contract["Description"] + "\"}");
                total++;
            }
        } 

The Flexbox appears and I am able to enter data but every time it comes up with no results found.  If I change the contract code back to id then it again works.  Contracts are alpha numberic and are around 5-8 characters.

Any ideas?

Cheers

Cap

Aug 17, 2010 at 8:42 AM

Wow I'm an idiot!  The ID is an int while the contract code is a string.  The JSON is being generated as "id":code,"name":"code", the first code in that string is not an interger and hence needed to be in quotation marks.  I spent about 2 hours on this yesterday, get some sleep and it's sorted in 15 minutes!  Happy days :D