angular2 ----字符串、对象、base64 之间的转换

1. JSON对象转化为字符串

let obj = {

  "name":Ayinger;

  "sex":"女";

}

let str = JSON.stringify(obj);

//结果:str = " { "name" : "Ayinger" , "sex" : "女" } ";

2. 字符串转换为JSON对象

let obj1 = JSON.parse(str);

// 结果:obj1 = { name:"Ayinger" , sex:"女" };

3. 字符串转换为base64 (编码)

base64encoder(Context):any{

  let encoder = new Buffer(Context).toString(‘base64‘);

  return encoder;

}

4. base64换为 字符串转(解码)

base64decoder(Context):any{

  let decoder = new Buffer(Context,‘base64‘).toString();

  return decoder;

}

时间: 2024-08-11 15:45:31

angular2 ----字符串、对象、base64 之间的转换的相关文章

Java中字符串与日期之间的转换

项目过程中,经常遇到需要字符串格式的日期和Date类型的日期之间的相互转换.使用SimpleDateFormat类,可以方便完成想要的转换. SimpleDateFormat能够实现本地化的时间格式化及转换.从选定一个自定义的模式(pattren)开始,模式由已经定义好的 'A' to 'Z' 及 'a' to 'z'字母组成,也可以在模式中引入文本,但要使用’(单括号)括住.下图就是已经定义好的模式字母表: Letter Date or Time Component Presentation

字符串与数字之间的转换

1. itoa itoa是广泛应用的非标准c语言扩展函数,头文件为 #icnlude<stdlib.h> char* itoa(int value,char* string,int radix); #include<iostream> #include<cstdlib> using namespace std; int main(){ int i=15; char str[25]; itoa(i,str,16); cout<<str<<endl;

Java对象 json之间的转换(json-lib)

在这里主要简单的介绍一下,如何使用json-lib这个工具包来完成Java对象(或集合)与json对象(或集合)之间的转换~ 1. Java对象转换成json(既创建json) 关键类:JSONObject jsonObject = JSONObject.from(Object obj); 使用说明:只要将Java对象传入方法,那么便可以得到一个JSONObject,然后你便可以直接json.toString();输出json~ 例子: @Test public void testCreateJ

C#字符串和数据之间的转换

c#中不仅仅存在数值类型的数据之间的转换,字符串和数值之间也是可以互相转换的,只是方法不同而已. 1 数值型转换为字符型 数值型数据转换为字符串用ToString()方法即可实现 int num1=10string mynum=num1.ToString(); 2 字符串转换为数值型 字符串数据转换为数值型使用Pares()方法字符串转换为整型用int.Pares() string str="13";int number=int.Pares(str);字符串转换为双精度浮点型  dou

字符串和数字之间的转换(Unicode)

1 Unicode编码的字符串转换为数字类型 CString str; str = _T("1234"); int i = _ttoi(str); float f = _tstof(str); 2 数字转换为wchar_t wchar_t c[10]; int num = 100; _itow_s(num,c,10,10进制); wstring str(c); 3 wstring 转换为int wstring str; _wtoi(str.c_str); 那么究竟什么是Unicode?

Qt中字符串和数值之间的转换

来自<Qt5.9 C++开发指南> 普通数值和字符串之间的转换 一.从字符串转换为数值 QString类从字符串转换为整数的函数有: int QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const long QString::toLong(bool *ok = Q_NULLPTR, int base = 10) const short QString::toShort(bool *ok = Q_NULLPTR, int base =

C/C++中字符串与数字之间的转换

主要有两种方式:C 中能够使用 sprintf 将数字转为字符数组,sscanf 将字符数组转为数字:而在 C++ 中不仅能够使用 C 中的方法,还能够使用 stringstream 实现字符串与数字间的转换. #include "iostream" #include "string" #include "sstream" #include "cstdio" using namespace std; string num2st

字符串和数组之间的转换

字符串-->数组 ① 转换成String类型的数组 String string = "abc,def,ghi"; String[] stringArray = string.split("\\,"); // java中通常用split()分割字符串,返回的是一个数组 for(String a : stringArray){ System.out.println(a); } ② 转换成char类型的数组 String string = "abc,def

JS 时间字符串与时间戳之间的转换

1.当前时间换时间戳 var timestamp = parseInt(new Date().getTime()/1000); // 当前时间戳 document.write(timestamp); 2.当前时间换日期字符串 var now = new Date(); var yy = now.getFullYear(); //年 var mm = now.getMonth() + 1; //月 var dd = now.getDate(); //日 var hh = now.getHours(