1

I have an AngularJS project that is getting a RESTful API response from Blogger, in the response the content of the blog which is received as an HTML segment is wrapped in double quotations. I need to remove the double quotations from the JSON response so the HTML will render as code instead of a string. I have tried the solutions found on here but cannot get them to work. Any help would be greatly appreciated. Here is the response, I trimmed non relevant data:

"kind": "blogger#postList",
"items": [   {
  "content": "<div dir=\"ltr\" id=\"docs-internal-guid-24696b56-798c-8f73-9921-a7bab5aae617\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: center;\">\n<br><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The sound of that question already gives most people Anxiety. All of the hassle can be so overwhelming, the New Place? Packing? Storage? Movers? Right in the middle of all that chaos most people forget to know where to start, that is where these helpful tips can come into your life and make sense of your struggles. <\/span><\/div>\n<ol style=\"margin-bottom: 0pt; margin-top: 0pt;\">\n<li dir=\"ltr\" style=\"font-family: Arial; font-size: 14.6667px; list-style-type: decimal; vertical-align: baseline;\"><div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-size: 14.6667px; vertical-align: baseline;\">Get rid of all that clutter! <\/span><\/div>\n<\/li>\n<\/ol>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">All people say to Spring Clean, most reply with, “Oh, I did it last year”. Well, there is an old 6 to 12 month rule, if you haven't seen it, used it or worn it in the past 12 months and don't see yourself using it or wearing it in the next 6 months donate it or give it away.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2. Think about it!<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">Are the things you're packing going into storage or to the new place? If any storage items come up, package them first and move on to the things you are taking to the new place.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3. Supplies…<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">Self explanatory, what is it you are packaging and what will you need to secure it to make it safely to its new destination?<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• Boxes - height, size, and condition are the best things to take into consideration. The right size of boxes can help determine space used and what is left to fill it securely ( not too big, not too small, but just right). The condition of the box should be sturdy enough to handle your possessions without the box falling apart.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• Tape - strong and durable, and never underestimate the dispenser. Many times people overlook it but truly it is worth the extra expense. If you think about it, it keeps the tape from sticking to itself (which can cause you to tear off small sections of it unevenly while trying to unstick it, and can cause your fingers to get caught in the crossfire).<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">The dispenser also helps to guide the tape around the box(In which case, if you didn't have it and you missed the connecting flap of your box it will fall apart. What a mess)!<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• Permanent Marker - ok, some say yes and some say, “who cares it's all going to the same place”. Well, we would have to agree that having the permanent marker is a handy idea. It is so simple to mark a box, you mark your boxes location or destination, so when you get to the new location you or the movers can place it in the appropriate room. So, for example, when you do unpack you don't wind up with a box of shoes where your pots and pans should be. It takes less than one minute, and can save you hours of distress.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• Fillers - packaging peanuts, foam, clothes, saran wrap.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">For big pieces of furniture that cannot be boxed, use foam around sharp corners and saran wrap the foam and any drawers so nothing and no one gets hurt or falls out. Packaging peanuts or paper, or even some clothes that you don't need until you get to the new location are great supplies to keep your things secure. Wrap up the valuables or fill empty space enough to where, when you move the box around you don't hear or feel shifting in the box.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;4. Essentials …<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">What ever you are going to need with you during the move, for example, clothes, toiletries, food, movies, etc. Get luggage bags ( never pack luggage bags, use them) and fill them up with enough supplies to last you through the entire move including the day after your arrival. Put them aside with a big note: FOR MOVE, DO NOT PACK!! It works great, so when the movers come they will not pack away your essentials.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;5. Organize…<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">The biggest thing to remember when packing is to always try to put things together as a group, so when unpacking comes around you are not putting 20 things in 10 different places. For example, the box’s label states KITCHEN, you open it and all pots and pans are there. GREAT! It all goes in the same cabinet and you're done. Instead of, some pots, some plastic cups, some silverware. Some of “whatever” always means more to come. Keep ALL of “whatever” ALL together.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;6. Movers??<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">Once everything is packed and ready to go, call the movers and they take more stress off of you physically and emotionally. Remember, this is what they are trained to do and they have all the right equipment to get your things safely to their new destination.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"> &nbsp;&nbsp;&nbsp;&nbsp;7. Get In The Car!!<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;\">\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">Now that all your things are packed and ready to go, and the movers have already put your things in the truck, it's time to pack you and your family in the car. Grab your essentials put on your seatbelts and head towards YOUR new beginning! Good luck!<\/span><br>\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\"><br><\/span>\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">Move It All Services<\/span><br>\n<span style=\"font-family: &quot;arial&quot;; font-size: 14.6667px; vertical-align: baseline;\">www.moveitallservices.com<\/span><\/div><div dir=\"ltr\" style=\"margin-bottom: 0pt; margin-top: 0pt;\"><font face=\"arial\"><span style=\"font-size: 14.6667px; line-height: 20.24px;\">Www.yelp.com/biz/move-it-all-services-sterling<\/span><\/font><\/div>\n",
  }],
}

To make things a bit more readable here is the Angular for the response with the fix I have tried:

$http({
        // method: 'jsonp',
        url: 'https://www.googleapis.com/blogger/v3/blogs/5365791431688522525/posts?key=PRIVATE'
        // params: {limit: '3'}
    }).success(function (data, status) {
        $scope.blogPosts = data;
        $scope.blogPosts.items.content = string.replaceAll("^\"|\"$", "");
        console.log($scope.blogPosts);
    }).error(function (data, status) {
        $scope.blogPosts = data;
        console.log('Something went wrong')
    });

Let me also add I am using Angular 1.3.11

Vessaredan
  • 49
  • 1
  • 11
  • Can you post some code that you have tried, and the output that you get? Folk here can help you to fix it. Please edit the question to add this information. – EkcenierK Dec 28 '15 at 19:07
  • 1
    Are you using [ngBindHtml](https://code.angularjs.org/1.3.10/docs/api/ng/directive/ngBindHtml)? – JoseM Dec 28 '15 at 19:07
  • 1
    why you can not use `elm.innerHTML = items[0].content;` ? It`s looks like a valid html, no double escaped quotes etc... – h0x91B Dec 28 '15 at 19:08
  • Here is the Angular success for handling the response that I have tried: $http({ // method: 'jsonp', url: 'https://www.googleapis.com/blogger/v3/blogs/5365791431688522525/posts?key=PRIVATE' // params: {limit: '3'} }).success(function (data, status) { $scope.blogPosts = data; $scope.blogPosts.items.content = string.replaceAll("^\"|\"$", ""); console.log($scope.blogPosts); – Vessaredan Dec 28 '15 at 19:15

0 Answers0