Изменить данные в Json, полученные через GET в JS

Тема в разделе "JavaScript", создана пользователем silmarion, 25 окт 2014.

Модераторы: ZiX
  1. silmarion

    silmarion

    Регистр.:
    21 июн 2012
    Сообщения:
    194
    Симпатии:
    19
    Добрый день всем, есть скрипт, который подгружает Json данные из стороннего файла, и выводит их на страницу.

    Необходимо получать эту инфу, и менять в ней данные перед выводом на страницу. Это возможно?
    Вот пример получаемых скриптом данных
    Код:
    {"description":"Gorgeous2 BR + den that can be converted into a 3 bedroom. Custom finishes throughout, including luxurious marble and substantial upgrades. Private elevator, S/S appliances and never ending views! Flow through floor plan with both East and West Exposures.","features":{"Appliances":["Dishwasher","Dryer","Icemaker","Microwave","Electric Range","Refrigerator","Washer"],"Restrictions":["No Restrictions"],"Furnished":["Furnished"],"Waterfront":["Bay Front"],"Flooring":["Marble Floors"],"Cooling":["Central Cooling"],"Master Bedroom/Bath":["Dual Sinks"],"Amenities":["Business Center","Cabana","Community Room","Exercise Room","Other","Child Play Area","Pool","Sauna"],"Interior":["Elevator","Foyer Entry","Walk-In Closets"],"Maintenance Fee Includes":["Common Area","Manager","Water"],"Governing Bodies":["Condominium"],"Construction":["Pre-Cast Concrete Construction"],"HOA Fee/Month":["1169"],"Security":["Doorman","Elevator Secure","Lobby Secured"],"Heating":["Central Heat"],"Garage/Carport":["1"],"Dining Area":["Dining/Living Room"],"Exterior":["Open Balcony"],"Pet Restrictions":["More Than 20 Lbs"],"Parking":["1 Space"],"Application Fee":["0"]},"_id":"74_A1988767","address":"2020 North BAYSHORE DR","tax_year":"2013","high_school":null,"short_sale":false,"indexed_dts":"2014-10-24T07:08:24Z","building":"Paramount Bay","taxes":14673,"idx_detail_disclaimer":"The data relating to real estate for sale on this web site comes in part from Miami Association of Realtors, Realtor Association of Greater Ft. Lauderdale, and the South Broward Board of Realtors.\n \nInformation is deemed reliable but not guaranteed. Copyright 2014, Miami Association of Realtors, Realtor Association of Greater Ft. Lauderdale, and the South Broward Board of Realtors. All rights reserved. The information being provided is for consumers' personal, non-commercial use and may not be used for any purpose other than to identify prospective properties consumers may be interested in purchasing. Use of search facilities of data on the site, other than a consumer looking to purchase real estate, is prohibited.\n \nListing Courtesy of: Douglas Elliman\n","internal_id":"339814619","listing_agent_id":"3274283","images":["http://cdn.showcaseidx.com/mls_images/74/A198/A1988767/339814619-1.jpg","http://cdn.showcaseidx.com/mls_images/74/A198/A1988767/339814619-2.jpg","http://cdn.showcaseidx.com/mls_images/74/A198/A1988767/339814619-3.jpg"],"middle_school":null,"listing_office_id":"DEOM10","city":"Miami","county":"Miami Dade, FL","year_built":"2011","longitude":-80.187133,"state":"FL","subdivision":null,"property_type_id":2,"first_seen_dts":"2014-08-16T07:09:26Z","orig_mls_number":"A1988767","img_change_dts":"2014-10-02T10:39:15.000Z","elementary_school":null,"status":"Active-Available","zip":"33137","bedrooms":2,"lnglat":[-80.187133,25.795681],"citystate":"Miami, FL","mls_number":"74_A1988767","unit_number":"906","virtual_tour_url":"http://instatour.propertypanorama.com/instaview/mia/A1988767","listing_agent":null,"latitude":25.795681,"listing_office":"Douglas Elliman","foreclosure":false,"bathrooms":2,"service_id":74,"sqft":1782,"price_change_dts":null,"price":1000000,"latlng":[25.795681,-80.187133],"halfbaths":1,"skip":false}
    
    мне нужно перед тем как скрипт выведет инфу на страницу изменить некоторые данные, к примеру:
    "Heating" сменить на "Отопление"
    "Sauna" сменить на "Сауна"
    ну и тд

    С меня пиво:beer:
     
    Последнее редактирование: 25 окт 2014
  2. PapaJoe

    PapaJoe

    Регистр.:
    4 авг 2008
    Сообщения:
    620
    Симпатии:
    312
    так ведь это обычный объект, т.е. в нём можно менять всё, что душе угодно:
    Код:
    r=JSON.parse('{"type":0,"sub":{"name":"1234","id":"153"}}');
    alert(r['sub']['name']);
    r['sub']['name']="4321";
    alert(r['sub']['name']);
     
    silmarion нравится это.
  3. silmarion

    silmarion

    Регистр.:
    21 июн 2012
    Сообщения:
    194
    Симпатии:
    19
    Я если честно в JS туго, могу по аналогу делать.
    Тут JS размером в 1мб подгружает на сайт объявления.
    Основная инфа которую нужно перевести грузится с ссылки пример:
    https://idx.showcaseidx.com/api/details/74_A1969689___21050_POINT_PL_Aventura_FL_33180

    Вроде как в js вот отсюда где то
    ...
    listing: [ "$http", "$stateParams", function(t, e) {

    return t.get("" + i + "/api/details/" + e.mls_number, {

    cache: !0
    });
    } ]
    ...

    Возвращает что писал выше.

    интересует в основном "features" в разных объявлениях количество пунктов различается.

    Выводится это всё к примеру тут:


    Вот к примеру:
    Код:
    "features":{
    "Appliances":["Dishwasher","Dryer","Icemaker","Microwave","Electric Range","Refrigerator","Washer"],
    "Restrictions":["No Restrictions"],
    "Furnished":["Furnished"],
    "Waterfront":["Bay Front"],
    "Flooring":["Marble Floors"],
    "Cooling":["Central Cooling"],
    "Master Bedroom/Bath":["Dual Sinks"],
    "Amenities":["Business Center","Cabana","Community Room","Exercise Room","Other","Child Play Area","Pool","Sauna"],
    "Interior":["Elevator","Foyer Entry","Walk-In Closets"],
    "Maintenance Fee Includes":["Common Area","Manager","Water"],
    "Governing Bodies":["Condominium"],
    "Construction":["Pre-Cast Concrete Construction"],
    "HOA Fee/Month":["1169"],
    "Security":["Doorman","Elevator Secure","Lobby Secured"],
    "Heating":["Central Heat"],
    "Garage/Carport":["1"],
    "Dining Area":["Dining/Living Room"],
    "Exterior":["Open Balcony"],
    "Pet Restrictions":["More Than 20 Lbs"],
    "Parking":["1 Space"],
    "Application Fee":["0"]},
    
    Данные в квадратных скобках меняются
    но в принципе список позиций одинаковый.

    Как мне найти хотя бы в какой переменной это отправляется на страницу чтобы внести изменения?

    Ребят, очень помощь нужна, хелп
     

    Вложения:

    • mydx2rus.zip
      Размер файла:
      212,1 КБ
      Просмотров:
      1
    Последнее редактирование: 26 окт 2014
  4. KillDead

    KillDead

    Регистр.:
    11 авг 2006
    Сообщения:
    890
    Симпатии:
    562
    Код:
    var json_obj = {"description":"OWNER SAYS SELL! BRING SERIOUS OFFER Walk into unobstructed ocean & intracoastal views & Golden Beach Landscapes. Dining & Breakfast area. Private elevator opens up to your own foyer.State of Art Club 25,000 sqf private Gym & Spa,billiard, garden,& media rooms;nail salon;intracoastal viewing pier;3 gorgeous swimming pools, millions in remodeling Lobby & new hurricane shutters. Life at the Point is like being on a permanent vacation! Best Schools in the area, high security level.550sqf wrap around balcony.","features":{"Appliances":["Washer","Wall Oven","Smoke Detector","Self Cleaning Oven","Electric Range","Microwave","Icemaker","Disposal","Dishwasher"],"Restrictions":["No Restrictions","Okay To Lease 1st Year"],"Furnished":["Unfurnished"],"Waterfront":["Canal Front","Intracoastal Front"],"Flooring":["Marble Floors","Wood Floors"],"Cooling":["Electric Cooling"],"Amenities":["Bike/Jog Path","Bbq/Picnic Area","Clubhouse-Clubroom","Elevator","Exercise Room","Extra Storage","Fishing Pier","Heated Pool","Library","Child Play Area","Pool","Sauna","Spa/Hot Tub","Tennis"],"Interior":["Bar","Built-Ins","Closets Cabinetry","Custom Mirrors","Foyer Entry","Laundry Tub","Pantry"],"Directions":["ACCESS THRU BISCANE & NE213 HEADING EAST, FOLLOW TO NE 214 FOLLOWING THE CURVE TO THE END, LAST BUILDING ON YOUR RIGHT"],"Maintenance Fee Includes":["All Amenities","Common Area","Cable Tv","Hot Water"],"Governing Bodies":["Condominium"],"Construction":["Concrete Block Construction"],"HOA Fee/Month":["1606"],"Security":["Doorman","Guard At Site","Elevator Secure"],"Heating":["Central Heat"],"Garage/Carport":["1"],"Dining Area":["Formal Dining"],"Exterior":["Open Balcony"],"Pet Restrictions":["Maximum 20 Lbs"],"Parking":["1 Assigned Space","Valet Parking"],"Application Fee":["100"]},"_id":"74_A1969689","address":"21050 POINT PL","tax_year":"2013","high_school":null,"short_sale":false,"indexed_dts":"2014-10-26T07:08:05Z","building":"The Point Atlantic III","taxes":9000,"idx_detail_disclaimer":"The data relating to real estate for sale on this web site comes in part from Miami Association of Realtors, Realtor Association of Greater Ft. Lauderdale, and the South Broward Board of Realtors.\n \nInformation is deemed reliable but not guaranteed. Copyright 2014, Miami Association of Realtors, Realtor Association of Greater Ft. Lauderdale, and the South Broward Board of Realtors.  All rights reserved.  The  information being provided is for consumers' personal, non-commercial use and may not be used for any purpose other than to identify prospective properties consumers may be interested in purchasing. Use of search facilities of data on the site, other than a consumer looking to purchase real estate, is prohibited.\n \nListing Courtesy of: Miami Red Square Realty\n","internal_id":"339609595","listing_agent_id":"3124028","images":["http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-1.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-2.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-3.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-4.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-5.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-6.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-7.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-8.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-9.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-10.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-11.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-12.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-13.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-14.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-15.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-16.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-17.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-18.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-19.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-20.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-21.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-22.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-23.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-24.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-25.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-26.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-27.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-28.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-29.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-30.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-31.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-32.jpg","http://cdn.showcaseidx.com/mls_images/74/A1969/A1969689/339609595-33.jpg"],"middle_school":null,"listing_office_id":"MRSQ01","city":"Aventura","county":"Miami Dade, FL","year_built":"2000","longitude":-80.124536,"state":"FL","subdivision":null,"property_type_id":2,"first_seen_dts":"2014-08-16T07:07:12Z","orig_mls_number":"A1969689","img_change_dts":"2014-06-27T12:28:38.000Z","elementary_school":null,"status":"Active-Available","zip":"33180","bedrooms":3,"lnglat":[-80.124536,25.971044],"citystate":"Aventura, FL","mls_number":"74_A1969689","unit_number":"806","virtual_tour_url":"http://tours.southfloridavirtualtour.com/public/vtour/display/220268?a=1","listing_agent":null,"latitude":25.971044,"listing_office":"Miami Red Square Realty","foreclosure":false,"bathrooms":2,"service_id":74,"sqft":2440,"price_change_dts":null,"price":990000,"latlng":[25.971044,-80.124536],"halfbaths":1,"skip":false};
    
    
    
    var slovar = {
    
      'owner': 'овнер',
      'sell': 'продажа'
    };
    
    
    var json_str =JSON.stringify(json_obj);
     
    for (var search in slovar){
    
      json_str =  json_str.replace(new RegExp(search,'gi') , slovar[search]);
    
    }
    
    
    var json_obj = JSON.parse(  json_str);
    console.log(json_obj);
     
    silmarion нравится это.
  5. silmarion

    silmarion

    Регистр.:
    21 июн 2012
    Сообщения:
    194
    Симпатии:
    19
    Спасибо большое, а куда мне всё это дело прикрутить?


    var json_obj = тут как я понимаю должна быть переменная из mydx2rus.js?

    Где-то в этом районе думаю?
    Код:
    listing: [ "$http", "$stateParams", function(t, e) {
    
    return t.get("" + i + "/api/details/" + e.mls_number, {
    
    cache: !0
    });
    
    } ]
    
     
  6. KillDead

    KillDead

    Регистр.:
    11 авг 2006
    Сообщения:
    890
    Симпатии:
    562
    попробуй сделать
    Код:
    
    listing: [ "$http", "$stateParams", function(t, e) {
    
    return t.get("" + i + "/api/details/" + e.mls_number, {
    
    cache: !0
    }).then(function(t) {
    console.log(t);
    
                            return t.data;
                        });
    
    
    } ]
    
    
    и посомтри- будет ли работать и если да- что выведет