示例#1
0
        private Weather CallbackResponse(string responseObj)
        {
            Weather weather = null;


            Org.Json.JSONObject weatherMain = new Org.Json.JSONObject(responseObj);

            Org.Json.JSONArray weatherArray = new Org.Json.JSONArray();
            weatherArray.Put(weatherMain);


            for (int i = 0; i < weatherArray.Length(); i++)
            {
                try
                {
                    Org.Json.JSONObject weatherObject = weatherArray.GetJSONObject(i);

                    JSONObject objectLocation = weatherObject.GetJSONObject("location");
                    JSONObject objectCurrent  = weatherObject.GetJSONObject("current");

                    //JSONObject objectrequest = objectCurrent.GetJSONObject("request");
                    //"request":{ "type":"City","query":"Tel Aviv-Yafo, Israel","language":"en","unit":"m"}

                    weather = new Weather();

                    weather.setTemperature(objectCurrent.GetString("temperature"));
                    weather.setDescription(objectCurrent.GetString("weather_descriptions"));
                    weather.setWind_kph(objectCurrent.GetString("wind_speed"));
                    string icon = objectCurrent.GetString("weather_icons");
                    icon = icon.Replace("[\"" + "https:\\/\\/assets", @"https://assets");
                    icon = icon.Replace("[", "");
                    icon = icon.Replace("]", "");
                    icon = icon.Replace("\"", "");
                    icon = icon.Replace(@"\/", "//");
                    icon = icon.Replace(@"\\", "//");
                    //Android.Net.Uri uri = Android.Net.Uri.Parse(icon);
                    //Android.Net.Uri uri = Android.Net.Uri.Parse(icon);
                    //icon = uri.Path;
                    //icon = uri.AbsolutePath;
                    weather.setPoster(icon);
                    weather.setIs_day(objectCurrent.GetString("is_day").ToString());
                    weather.setCloud(objectCurrent.GetString("cloudcover"));

                    weather.setLast_update(objectLocation.GetString("localtime"));
                    weather.setCountry(objectLocation.GetString("country"));
                    icon = objectLocation.GetString("name").Trim();
                    icon = icon.Replace(@"[", "");
                    icon = icon.Replace("[", "");
                    icon = icon.Replace(@"]", "");
                    icon = icon.Replace("]", "");
                    icon = icon.Replace("\"", "");
                    icon = icon.Replace("\"", "");
                    icon = icon.Replace("[\"", "");
                    //icon = icon.Replace('\'', (char)32);
                    weather.setCity(icon.Trim());         // "type":"City","query":"Tel Aviv-Yafo, Israel"
                    weather.setRegion(objectLocation.GetString("region"));
                    weather.setLocal_time(objectLocation.GetString("localtime"));
                    weather.setTz_id(objectLocation.GetString("timezone_id"));

                    //"localtime_epoch":1583177400,"utc_offset":"2.0"
                    //wind_degree":311,"wind_dir":"NW","pressure":1021,"precip":0,"humidity":60,"cloudcover":7,"feelslike":17

                    try
                    {
                        //weather.setImageView(Utils.GetImageViewFromhUrl(weather.getPoster()));
                        //weather.setImageView(new ImageView(Application.Context));
                        //Android.Net.Uri uri = Android.Net.Uri.Parse(weather.getPoster());
                        //weather.getImageView().SetImageURI(uri);
                    }
                    catch
                    {
                    }

                    if (WeatherList.Count < 4)
                    {
                        WeatherList.Add(weather);
                    }
                    else
                    {
                        WeatherList[currentListIndex] = weather;
                    }
                }
                catch (JSONException ex)
                {
                    MH_Utils.Utils.WriteToLog(ex.Message);
                    //Log.d("Error: ", ex.getMessage());
                    //ex.printStackTrace();
                }
            }


            return(weather);
        }
示例#2
0
        private void ChangeLogLevel(string result)
        {
            var jsonArray = new JSONArray(result);
            var jsonObject = jsonArray.GetJSONObject(0);

            var logLevelString = jsonObject.Get("level").ToString();
            var logLevel = LogLevel.FromString(logLevelString);
            var toEnable = (bool)jsonObject.Get("enable");
            SetLogLevel(logLevel, toEnable);
            var message = string.Format("Set logging level to {0}", logLevelString);
//            _logger.Info(message);
        }
示例#3
0
        public List<String[]> contactRequest(String token)
        {
            /* stops working after the first 10 because REST api limit */

            String output = httpRequest(token,"https://www.yammer.com/api/v1/users.json");

            if (output != "") {
                JSONArray jObject = new JSONArray (output); // json
                List<String[]> ppl = new List<String[]> ();

                //int c = 0;
                JSONObject data, tmp;
                String[] items;
                String uid,fname,lname,email,phone="",org,profilepicture,miniprofilepicture;
                //maybe use less memory because im using heaps apparently

                for (int i = 0; i < jObject.Length (); i++) {
                    //if(i < 8){//limit for now
                        data = jObject.GetJSONObject (i); // get data object
                        uid = data.GetString ("id");

                    //userdeets = httpRequest (token, "https://www.yammer.com/api/v1/users/" + uid + ".json");

                    //if (userdeets != "") {
                        //Console.WriteLine (uid);

                        //person = new JSONObject (userdeets); // get data object

                        fname = data.GetString ("first_name");
                        lname = data.GetString ("last_name");
                        email = data.GetString ("email");
                        profilepicture = data.GetString ("mugshot_url_template");
                        profilepicture = profilepicture.Replace ("{width}x{height}", "300x300");

                        miniprofilepicture = data.GetString ("mugshot_url");

                        tmp = data.GetJSONObject ("contact");
                        phone = tmp.GetString ("phone_numbers");

                        try{
                            tmp = new JSONArray (phone).GetJSONObject (0);
                            phone = tmp.GetString ("number");
                        }
                        catch{
                            phone = "";
                        }

                        org = data.GetString ("network_name");

                    //Console.WriteLine (fname + " : " + lname + " : " + email + " : " + phone + " : " + org + " : " + uid);

                        items = new String[] { fname, lname, email, phone, org, uid, profilepicture, miniprofilepicture };
                        ppl.Add (items);
                        tmp.Dispose ();
                        data.Dispose ();

                        fname = "";
                        lname = "";
                        email = "";
                        phone = "";
                        org = "";
                        uid = "";
                        profilepicture = "";

                    //}//individual users
                    //c++;

                    //}//limit

                }//loop
                jObject.Dispose();

                return ppl;

            }//get all users

            return new List<String[]>();
        }