How to preserve object property casing when using Rxjs map function

白昼怎懂夜的黑 提交于 2019-12-11 01:52:06

问题


I am new to Angular2 and using http service to get data from asp.net mvc webapi.
API returns data which is in format shown below

RequestResponse{
    public string Message {get;set;}
    public int Status {get;set;} 
}

Http get request gets data and is fed to map function from Rxjs map(result => result.json()) which will convert result into format as shown below

{
    message : 'success!',
    status : 1
}

As you can see, output property names have lost case sensitivity.
Have read from other SO questions that we have to write our own mapper function to preserve case sensitivity.
My doubt is, is it possible to configure mapper function from Rxjs to preserve case sensitivity? or should we write our own mapper function?

EDIT: It seems that the issue is from .json() (?) Why .json() transforms property names into lowercase?

EDIT: Solution: Thanks @Sergey for the clue. The issue is from .Net Core which was by default converting property names to camelCase. If anybody searcing for the solution, please visit Github page.


回答1:


Map is a simple function that allows you to transform your data. It fits ideally for your needs:

request.map(response => {
  let data = response.json();
  return <RequestResponse> {
    Message: data.message,
    Status: data.status
  };
});


来源:https://stackoverflow.com/questions/41297396/how-to-preserve-object-property-casing-when-using-rxjs-map-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!