API commonly used background parsing XML, JSON data in two ways (JSON)

  ///  <summary> 
        ///   Get the data of the specified item number (ebay)
         ///  </summary> 
        ///  <param name="appid"> ebayApi appid </param> 
        ///  <param name=" _IncludeSelector"> Query content (Details, ShippingCosts, Variations, Description) </param> 
        ///  <param name="itemid"> Item number </param> 
        ///  <returns></returns> 
        public  string GetItem( string appID, string _IncludeSelector, string itemid)
        {
            string url = string.Format("http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=JSON&appid={0}&siteid=0&version=863&IncludeSelector={1}&ItemID={2}", appID.Trim(), _IncludeSelector, itemid.Trim()).Trim();
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "Get";
            req.ContentType = "application/json";
            req.ReadWriteTimeout = 12000; //12秒链接不成功就中断
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            var respneshtml = string.Empty;
            using (StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.UTF8))
            {
                respneshtml = sr.ReadToEnd();
            }
            return respneshtml;
        }

This is an eBay API for getting item details 

            //GET DATE
            string getdate = _goodBLL.GetItem(appID, _IncludeSelector, itemid);

            // Convert to JSON format 
            JObject o = JObject.Parse(getdate);
             // Attribute assignment           

            // Item description 
            if (o[ " Item " ][ " Description " ] != null )
            {
                _itemdateModel.Item_Description = o["Item"]["Description"].ToString();
            }

Normally, if a parent node contains a child node, it can be obtained by the above method.

Unconventional use of JA for a parent node to correspond to a child node

  // Picture 
            List< string > picture = new List< string > ();
             // Get the number of pictures 
            if (o[ " Item " ][ " PictureURL " ] != null )
            {
                int Picturecount = ((JArray)o["Item"]["PictureURL"]).Count;

                // Bind the value to the picture 
                if (Picturecount > 0 )
                {
                    for (int picIndex = 0; picIndex < Picturecount; picIndex++)
                    {
                        picture.Add(o["Item"]["PictureURL"][picIndex].ToString());
                    }
                }
                // End of binding value to picture
                 // Picture assignment 
                _itemdateModel.Item_PictureURL = picture;
            }

This is the background parsing method of JSON. It is also very simple~ Without accumulation, there is no way to go a thousand miles, and no matter how small the stream is, there is no way to make a river.

rray

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324779821&siteId=291194637