[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Decode \u003d and other \u code

Posted on 2009-04-10
4
Medium Priority
?
4,242 Views
Last Modified: 2012-06-27
In a JSON feed Google Base converts this URL:
http://www.realtybargains.com/guest/PropertyDetails.rb?PID=2789602&GB=search&rs=google

Into this:
http://www.realtybargains.com/guest/PropertyDetails.rb?PID\u003d2789602\u0026GB\u003dsearch\u0026rs\u003dgoogle

Using only JavaScript, how can I convert it back?

I don't want to simply replace this:
        \u003d
with this:
        =

Because there could be other characters in other links that are also encoded.  I would like to figure out the significance of this
      \u003d

and properly decode the JSON code they send me.

Thanks!


0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24115130
Here is a continuation of one I did earlier this week

you want ncr2utf(str)

<script>
 function d2h(d) {return d.toString(16).toUpperCase();}
function h2d(h) {return parseInt(h,16);} 
 
 function ncr2utf(str) {
   var chars = str.replace(/\&\#/g,'').split(';')
   for (var i=0;i<chars.length;i++) if (chars[i]) chars[i]="\\u"+d2h(parseInt(chars[i]));
   return chars.join(''); 
 }
 
 function utf2ncr(str) {
   var chars = str.split('\\u')
   for (var i=0;i<chars.length;i++) {
   	  alert(i+':'+chars[i])
   	  if (chars[i]) chars[i]="&#"+h2d(chars[i])+';';
   }
   return chars.join(''); 
 }
 
 var str = "&#49548;&#44060;"
 document.write(str.replace(/&/g,'&amp;')+':['+str+']:['+ncr2utf(str)+']:['+utf2ncr(ncr2utf(str))+']') //  should become \uC18C\uAC1C.
 </script>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24115211
oops, not totally what you wanted.. Give me a minute
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24115404
No need
Just assign it to a string and it will convert
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 24115406
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question