Parsing JSON in swift inconsistent
<p>I'm running into what I believe to be a bug. I have an array of objects returned from a server. However, when pulling values out of them I get inconsistent results. Each of these items are in the same array of the response from server: </p>

<p>When I try to pull the <code>quantity</code> value of this one it returns as in <code>Int</code>: </p>

<pre><code>{
    address = "4040 MARKET ST RM 226";
    city = PHILADELPHIA;
    ln = "AMOXICILLIN 500 MG CAPSULE";
    ndc = 57237003105;
    npi = 1619912375;
    "pharmacy_name" = "GRACE PHARMACY INC";
    phone = "(215)895-5594";
    price = "8.00";
    quantity = 500;
    state = PA;
    vendor = una;
    zip = 19104;
}
</code></pre>

<p>However, when I try to pull <code>quantity</code> from this one, it's returned as a <code>String</code>. </p>

<pre><code>{
    address = "1826 Chestnut St # 30";
    brand = G;
    city = Philadelphia;
    distance = "0.06";
    latitude = "39.951747";
    ln = "AMOXICILLIN 500 MG CAPSULE";
    longitude = "-75.171154";
    "ncpdp_id" = 3969485;
    ndc = 65862001705;
    "pharmacy_hours_of_operation" = "Open 24 Hours";
    "pharmacy_name" = "CVS PHARMACY";
    phone = "(215)972-0909";
    price = "11.82";
    quantity = 30;
    state = PA;
    vendor = scriptsave;
    zip = "19103-4902";
}
</code></pre>

<p>Why in the world would this be occurring? Both objects seems to be identical except for some extra values in one. </p>

<p>===</p>

<p>Serializing the JSON like this: </p>

<pre><code>let searchResultsJSON: NSDictionary = try NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableContainers) as! NSDictionary
</code></pre>

<p>Grabbing the values like this:</p>

<pre><code>    quantity            = formDictionary["quantity"] as? Int
    quantityString      = formDictionary["quantity"] as? String
</code></pre>

<p>====</p>

<p>Here is the JSON: </p>

<pre><code>results =     (
                {
            address = "4040 MARKET ST RM 226";
            city = PHILADELPHIA;
            ln = "ESOMEPRAZOLE MAG DR 40 MG CAP";
            ndc = 13668015510;
            npi = 1619912375;
            "pharmacy_name" = "GRACE PHARMACY INC";
            phone = "(215)895-5594";
            price = "74.00";
            quantity = 1000;
            state = PA;
            vendor = una;
            zip = 19104;
        },
{
            address = "1700 Market St";
            brand = G;
            city = Philadelphia;
            distance = "0.22";
            latitude = "39.952981";
            ln = "ESOMEPRAZOLE MAG DR 40 MG CAP";
            longitude = "-75.168431";
            "ncpdp_id" = 3985059;
            ndc = 00378235193;
            "pharmacy_hours_of_operation" = "S(Clsd) M(8a-6p) T(8a-6p) W(8a-6p) T(8a-6p) F(8a-6p) S(9a-12p)";
            "pharmacy_name" = "PICKWICK PHARMACY INC";
            phone = "(215)563-4860";
            price = "241.23";
            quantity = 30;
            state = PA;
            vendor = scriptsave;
            zip = "19103-3913";
        }
    );
</code></pre>

<p>So here, <code>quantity</code> in the first one is returned as an <code>Int</code> and as a <code>String</code> in the second one. I beginning to think this is a server side issue...</p>

<p>===</p>

<p>Looking at the JSON in Chrome does confirm that it's an encoding error from the server. Thanks @CouchDeveloper </p>

<p><a href="https://i.stack.imgur.com/mhHKM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mhHKM.png" alt="enter image description here"></a></p>