Get key and value from json array in ts file

I am testing ionic4 app. one http post value response is like below

var link = ‘http://localhost/testapi/index.php/Login/login’;

var myData = JSON.stringify({username: this.loginForm.value.username,password:this.loginForm.value.password});, myData)

.subscribe(data => { = data["_body"];

console.log(; // result is like ==>


I need to separate each key and its value in this ts file.

like status=true,username=as etc

I got this solution for my problem

var test= JSON.parse( ;
var key;
for (var event in test) {
var dataCopy = test[event];
for (test in dataCopy) {
var mainData = dataCopy[test];
for (key in mainData) {

          console.log( key + ' : ' + mainData[key]);




By convention, leading underscores mean “hands off”. If you’re using HttpClient, all you have to do is properly type your post call. This can all be simplified into a one-line function:

interface LoginRequest {
  username: string;
  password: string;

interface LoginResponse {
  status: boolean;
  token?: string;
  // other stuff here

login(req: LoginRequest): Observable<LoginResponse> {
  return<LoginResponse>(link, req);