I have received a Json object and I am looking to extract the data using JavaScript. Specifically, I need help with looping through fields and extracting the data.
def For_Sale_Listing(request,id):
try:
listing = Listing.objects.filter(pk=id)
listing_json = serializers.serialize("json", listing)
except Listing.DoesNotExist:
raise Http404('listing not found!')
data = {"listing_json": listing_json}
return JsonResponse(data)
$.ajax({
url: "/For-Sale-Listing"+"/" + parseInt(data[0]),
type: "GET",
data: {'Subscription': 1},
success: function(data) {
console.log(JSON.parse(data.listing_json));
},
error: function(xhr, status, error) {
}
});
I need to iterate through JSON fields using JavaScript
[{"model": "listings.listing", "pk": 3, "fields": {"property_type": 1, "user": 1, "price": 13000000, "roomsTotal": 78, "Bathrooms": 6, "bedrooms": 67, "Receptionrooms": 67, "livingArea": "67.000", "lotSize": "67.000", "unitType": 1, "yearBuilt": null, "remodelYear": null, "hoaPrice": null, "groundTankSize": null, "garageSize": null, "homeDescription": "", "whatYouLoveDescription": "", "Dishwasher": false, "Dryer": false, "Freezer": false, "GarbageDisposal": false, "Microwave": false, "Oven": false, "Refrigerator": false, "Washer": false, "RadioGroup_Rashan": null, "ACarpet": false, "AConcrete": false, "ATiles": false, "ALinoleum": false, "ADSoftwood": false, "ADOther": false, "BreakfastNook": false, "DiningRoom": false, "FamilyRoom": false, "LaundryRoom": false, "Library": false, "MasterBath": false, "Office": false, "Workshop": false, "roomCount": null, "attic": false, "cableReady": false, "ceilingFan": false, "doublePaneWindows": false, "fireplace": false, "intercom": false, "jettedTub": false, "securitySystem": false, "CCentral": false, "CEvaporative": false, "CGeothermal": false, "CRefrigeration": false, "CSolar": false, "CWall": false, "COther": false, "CNone": false, "HForcedAir": false, "HGeothermal": false, "HHeatPump": false, "HRadiant": false, "HStove": false, "HWall": false, "HOther": false, "FCoal": false, "FElectric": false, "FGas": false, "FOil": false, "FPropaneButane": false, "FSolar": false, "FWoodPellet": false, "FOther": false, "FNone": false, "basketballCourt": false, "doorman": false, "elevator": false, "fitnessCenter": false, "gatedEntry": false, "nearTransportation": false, "tennisCourt": false, "RadioGroup_Architectural": null, "Brick": false, "CementConcrete": false, "Stone": false, "EOther": false, "FloorCount": null, ...