Click here to Skip to main content
15,938,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
for (var i = 0; i < postcodeArr.length; i++) {
            var pstcd = postcodeArr[i];
            if (i == 0)
                jsonstring = "{'PostalCode': '" + pstcd + "' ";
            else {
                jsonstring += "," + "'PostalCode': '" + pstcd + "' ";
            }
        }
        jsonstring += "}";
        //jsonstring = JSON.stringify(jsonstring);
        //alert(jsonstring);
        var arrGPDetails = [];
        var dataString = 'servicetype=GPPostcode&data=' + jsonstring;


GPDetails objGPpost = jSer.Deserialize<GPDetails>(data);

GPDetails properties are given below
JavaScript
public string PostalCode { get; set; }

What i required is i will get more than one postcodes in to objGPPost objects and i need to assign into Postalcode. But i am getting only one postal code. Multiple not getting assigned into PostalCode.

I tried putting public string PostalCode { get; set; }

However when i am doing so it throws an exception
ex = {"Cannot convert object of type 'System.String' to type 'System.String[]'"}

How to solve this issue.
Thanks in advance
Posted
Updated 17-Feb-14 21:53pm
v2
Comments
Krunal Rohit 18-Feb-14 4:18am    
at which line are you getting exception ?
Trajan McGill 18-Feb-14 9:49am    
I'm not sure exactly what you're trying to accomplish, or what the GPDetails class or structure looks like, but I can tell you for one thing that the string you're putting in the jsonstring variable doesn't define an array. An array in Javascript looks like this:
"[1, 2, 3]".

You are building a string that looks like this:
"{'PostalCode':'12345', 'PostalCode':'23456', 'PostalCode':'34567'}"
and that is the definition of an object with the same property ("PostalCode") defined over and over again.

You may be intending to build a JSON string more like this:
"{'PostalCodes':['12345', '23456', '34567']}"
or possibly like this:
"{'PostalCodes':[{'PostalCode':'12345'}, {'PostalCode':'23456'}, {'PostalCode':'34567']}"
depending on what you're trying to do with the resulting array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900