Unlocking a peculiar artifact

How do I retrieve the keys and values from the following...

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c797f697e7f4c69616d6560226f6361"> [email protected] </a>{"authenticated": "TRUE", "devid": "12334567890"} 

This information will be utilized for logging in. I am sending an http post request to a php backend.

I need to verify if authenticated == true, and also access the value of devid.

While iterating through is one option, I understand that the email address will vary for each user. So, how can I access this changing object?

Answer №1

To achieve this, follow these steps:

let fileData ='<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="651016001716250008040c094b060a08">[email protected]</a>{"authenticated":"TRUE","devid":"12334567890"}';
let str1 = fileData.split('{');
let str2 = str1[1].split('}');
let result = JSON.parse('{'+str2[0]+'}');
alert(result.authenticated);

The flag can be found in the pos.authenticated property.

Answer №2

Give this a shot:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  
  $scope.users = {"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6d3d5c3d4d5e6c3cbc7cfca88c5c9cb">[email protected]</a>": {"authenticated":"TRUE","devid":"12334567890"}}
  var id = Object.keys($scope.users);
  console.log(id);
 console.log($scope.users[id[0]].authenticated);
  
  
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
 <body ng-app="plunker" ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
  </body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for saving a document in a table without using the _id field

I want to save the employee object without the _id attribute, just the "employee" attribute as shown below: "employee" :[ { "name" : "leila", "idemployee" : ObjectId("59319505efa50b137477a1f4"), ...

Picture disappearing following the refresh of an AJAX iframe

Currently, I am developing a profile system where the user's profile is displayed in an iframe that reloads when the form submit button is clicked. The content updates successfully upon reloading, but there is an issue with images not displaying after ...

Using forRoot does not trigger Angular lazy loading functionality

I have implemented a lazy load module that needs to expose providers by utilizing the forRoot convention and returning the following code: @NgModule({ imports: [RouterModule.forChild([ {path: "", component: LazyComponent}, ])], declarations: [La ...

Display information from dynamically generated pages using Gatsby JS sourcing data from CSV files

I've been working on creating pages in Gatsby JS from a csv file and everything seemed to be going smoothly. However, when it comes to displaying the data on these generated pages, I keep running into issues with undefined variables and can't see ...

Disable the click functionality while preserving the hover feature

Due to my previous question being incorrectly marked as a duplicate, even though it wasn't, and no one is rectifying the mistake, I am re-posting my inquiry. I am dealing with an <a> element that has a default onClick function. This <a> a ...

Model of Objects within a Document

Here's a puzzling question for you: why does console.log(document.body) and console.log(document.head) work perfectly fine, but console.log(document.script) or console.log(document.html) don't seem to do anything? It's strange because all of ...

Tips for simulating services in unit tests for directives?

A directive I'm working on involves an apiService that acts as a wrapper for $http and other custom services. When attempting to test the directive, I am unsure of how to mock the service: app.directive('coreMenu', ['apiService', ...

Creating a TypeScript class with methods to export as an object

Just dipping my toes into Typescript and I've encountered a bit of a challenge. I have a generic class that looks like this: export class Sample { a: number; b: number; doSomething(): any { // return something } } My issue ari ...

Deleting elements from the DOM in Vue.js

Utilizing Vue.js (version 3.x), I am dynamically rendering components. <div v-for="(i, index) in fields" > <my-component :id="index" ></my-component> <span class="delete-icon" @click="removeFi ...

Sometimes the Navbar options fail to show up consistently on the Navbar bar

I recently launched my website at campusconnect.cc Unfortunately, I've noticed that when resizing the window, the navbar options are shifting up and down. Can anyone help me identify the issue and provide guidance on how to resolve it? ...

Obtain Insights into Community Tab Information on Youtube using Python

I have been attempting to retrieve information from the Community Tab of a YouTube channel, but it appears that this feature is not supported by the YouTube API that I've been utilizing. Despite my efforts, which include parsing the HTML, I have not b ...

Modifying JSON data in a file using Node.js

I am new to working with JSON files and I have a specific task that I need help with. I have a JSON file containing multiple objects, and I want to extract data from the file, update a value within one of the objects, and then save the changes back to the ...

Sending images as a base64 string from a Titanium app to a Ruby on Rails web service

I am encountering an issue when trying to upload an image from an app that has been converted into a base64 string to a Ruby on Rails server. The app is developed using Titanium. However, after retrieving and decoding the image string back into an image, ...

AngularJS and ASP Controller API encountering CORS problem while being hosted on separate servers within a local network

I am facing an issue with my ASP application hosted on a server within a local network. Whenever I make an OPTION request from AngularJS, it returns a 200 status but throws an error. Below is the GET code in Angular: var config = { headers: { ...

When a user clicks a button, modify a section of the URL and navigate to

I've been searching everywhere for a solution to this issue, but I just can't seem to find it. I'm hoping someone here can help me out. In a bilingual store, I need a way to redirect users to the same product on a different domain when they ...

What is the best way to store settings values permanently during the installation process in a react-native application?

I am looking for a way to save the settings of my app only during installation, rather than every time the app is opened, in order to prevent the options from resetting. I have tried searching on YouTube but most tutorials cover only user login persistence ...

Display a dynamic array within an Angular2 view

I have a dynamic array that I need to display in the view of a component whenever items are added or removed from it. The array is displayed using the ngOnInit() method in my App Component (ts): import { Component, OnInit } from '@angular/core' ...

Error message: 'Encountered issue with react-router-V4 and the new context API in React

Currently, I am experimenting with the integration of React Router V4 alongside the new React context API. Below is the code snippet I am working with: class App extends Component { static propTypes = { router: PropTypes.func.isRequired, ...

What steps can I take to resolve the operating system error I am encountering while attempting to send a request using restify-clients to a restify server with the Commander cli

Greetings in advance. Typically, I solve issues without asking for help, but I am currently facing what seems to be an operating system error that has left me stumped. If you require additional details, feel free to reach out. I am dealing with three pri ...

Having trouble getting a Chrome extension/jQuery to work on certain sites but not others? Attempting to trigger an event when a link is clicked

For three different websites, I have three separate js files. I want to mention that the manifest has the correct settings to make sure these files work on the right sites, but unfortunately, only one function of the extension (the most important one) is n ...