示例#1
0
        private void sendBackKnownValue(String descriptionValue)
        {
            UPCSvcs_SendBackJSON.sendbackRoot return_json = new UPCSvcs_SendBackJSON.sendbackRoot();
            return_json.response_type         = "KnownValue";
            return_json.known_description     = descriptionValue;
            return_json.possible_descriptions = new List <UPCSvcs_SendBackJSON.aDescr>();

            String jsonResponse = JsonConvert.SerializeObject(return_json);

            Response.Write(jsonResponse);
        }
示例#2
0
        private void sendBackPossibleValues(String upcvalue)
        {
            String urlToSend = "https://api.upcitemdb.com/prod/trial/lookup?upc=" + upcvalue;

            var possibleDescriptions = new List <string>();
            int ndx, lastNdx;
            int ndx2, lastNdx2;

            // ** need to check for failure, or item not found
            WebClient    webClient        = new WebClient();
            Stream       response         = webClient.OpenRead(urlToSend);
            StreamReader responseData     = new StreamReader(response);
            String       responseAsString = responseData.ReadToEnd();

            response.Close();
            // optional cleanup of returned JSON before deserialization
            //responseAsString = responseAsString.Replace("@", "");
            //responseAsString = responseAsString.Replace("?xml", "xmlinfo");
            //responseAsString = responseAsString.Replace("#cdata-section", "cdatasection");

            // hardcode the deserialization desired here
            PollWebServiceTest_UPC.UPCAPI s = JsonConvert.DeserializeObject <PollWebServiceTest_UPC.UPCAPI>(responseAsString);

            lastNdx = s.items.Count - 1;
            for (ndx = 0; ndx <= lastNdx; ndx++)
            {
                possibleDescriptions.Add(s.items[ndx].brand + " " + s.items[ndx].title + " " + s.items[ndx].size);

                lastNdx2 = s.items[ndx].offers.Count - 1;
                for (ndx2 = 0; ndx2 <= lastNdx2; ndx2++)
                {
                    possibleDescriptions.Add(s.items[ndx].offers[ndx2].title);
                }
            }
            //
            UPCSvcs_SendBackJSON.sendbackRoot return_json = new UPCSvcs_SendBackJSON.sendbackRoot();
            return_json.response_type         = "PossibleValues";
            return_json.possible_descriptions = new List <UPCSvcs_SendBackJSON.aDescr>();
            lastNdx = possibleDescriptions.Count - 1;
            for (ndx = 0; ndx <= lastNdx; ndx++)
            {
                UPCSvcs_SendBackJSON.aDescr a = new UPCSvcs_SendBackJSON.aDescr();
                a.description_value = possibleDescriptions[ndx];
                return_json.possible_descriptions.Add(a);
            }

            String jsonResponse = JsonConvert.SerializeObject(return_json);

            Response.Write(jsonResponse);
        }