Checking whether a JSON dictionary is empty or not and storing in a list


jwyse
26/4/2016 6:52 am
HOME ยป Web Development

I have an Instagram API which I load into a JSON. The response is coming properly and I am even able to fetch the id from the data received. Then I save it in a python list and put it in an Excel sheet using openpyxl.

Here is the catch. While loading the values, If there is no response from API in case of a deleted instagram account,where the JSON will be empty, I want to store "ACC deleted" in the list.

(NOTE :- I also referred similar questions but didnt get my answer which works.)

Here is the code:

for r in range(1,51):
    var=r,test.cell(row=r,column=1).value
    xy=var[1]
    myopener=Myopener()
   
url=myopener.open('https://api.instagram.com/v1/users/search?q='+xy+'&count=1&access_token=641567093.1fb234f.a0ffbe574e844e1c818145097050cf33')

    **beta=json.load(url)
    for item in beta['data']:
        list.append(item['id'])** //*HERE I WANT THE CHANGE*


    for j in range(len(list)):
        for row in sheet.iter_rows(min_row=j+1, max_row=j+1):
            for cell in row:
                cell.value=list[j]
                wb.save('sample.xlsx')

The json Response is this:

{
"meta":  {
"code": 200
},
"data":  [
 {
  "username": "rawhawk_sk",
  "profile_picture":
"https://scontent.cdninstagram.com/t51.2885-19/s150x150/12724928_109384759877664_1105313598_a.jpg",
  "id": "670907103",
  "full_name": "shwan mcswan"
}
]
}

If the json response is empty like below, how to store "ACC deleted" in the list?

{
"meta":  {
"code": 200
},
"data":  []
} 

Related to : Checking whether a JSON dictionary is empty or not and storing in a list
Checking whether a JSON dictionary is empty or not and storing in a list
26/4/2016 6:52 am by jwyse in Web Development

I have an Instagram API which I load into a JSON. The response is coming properly and I am even able to fetch the id from the data received. Then I save it in a python list and put it in an Excel sheet using openpyxl.

Here is the catch. While loading the values, If there is no response fr


Storing value and checking if the value is empty
by zclin in Web Development

Is there a way I can check if the value of


<?php the_field('max_working_height')?>

is empty or store the value that will be displayed when I use acnd check if that is empty or not. If the value is not empty then I have to make it execute a set of html


Checking if a key exists and its value is not an empty string in a Python dictionary
by lewing in Web Development

Is there a clear best practice for assigning a variable from a key/value pair in a Python dictionary:


If the key is present
If the key's value is not an empty string

And otherwise assigning a default value to the variable.


I would like to use dict.get TAGS: Checking exists value empty string Python

check if json dictionary has empty strings as a value
by XLNC in Web Development

what i am trying to achieve is to show and element only if an element's value within a JSON object is NOT equal to an empty string '.


For Example:

say i have the following json object


{
'id' : 23,
'name' : 'Adrian Reese',
'ag
checking for empty json in Titanium
by showb1z in Web Development

I have been looking at the problem of detecting an empty JSON object and could not get some of the suggestions to work that I found here.


The solution that seems to work is:


if ( Ti.JSON.stringify ( json ) != "{}" )

Does anyone see any problems with


c# deserialize json to list results in null when json is empty?
17/11/2014 5:40 am by CRaul87 in Web Development

I am facing this situation and it is really strange to me.

I have class A has the following

public class A
{

   public A()
   {   
      Values = new List<B>();
   }

   public virtual IList<B> Values { get; set; }
}

I have a method that wil


PHP AJAX JSON checking if data is empty
12/1/2015 9:50 pm by Isaac in Web Development

Still trying to familiarize myself with the ajax method.

Here's another one...

Currently, my code below is sending a partner-code to a php script and returning JSON data.

 $('a.pComment').on('click', function()
 {
   var partnercode = $(this).attr('data-code');
 
Checking an empty key in a complex JSON response
by Ph33zy in Web Development

I am unable to check if one of my keys is empty.


Following is the parsed JSON response I am working with :


Case 1 (key 'tags' is not empty)


{
height = 480;
pid = "a@bsioihf93u420934";
tags = (
{
attributes =
python assigning a list to a dictionary returns empty list
by AFurryReptile in Web Development

I have an issue whereby my list frameChain is being reflected as empty ([]). frameChain is actually a list such as: ['C Level', 'Medium Term']


jsonOut[x]= {'TEXT' : node.attrib['TEXT'],
'ID': node.attrib['ID'],

List or Dictionary for storing game map
by Sunny Dhillon in Web Development

So I currently have a 2d list of objects that define the map of a game where each object represents a tile on that map. As I was repurposing the code for something else, I wondered if it would make more sense to use a dictionary to store the map data or to continue using a list. With a list, the


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .