Select raw data value using JS/jquery


Well

I am trying to select values ​​from some raw data using jquery.
I have tried something like this The  var id = $("body").data("id");

original data looks like this  {"photo":{"id":85456501,"user_id":601182}}

Any ideas?

Mathias

You can get the raw data string inside this body element:

var rawData = $("body").text();

Every Javascript object is also a JSON string, so you can parse it like JSON.

var data = JSON.parse(rawData);

Now you can get the ID like this:

var id = data.photo.id
var userid = data.photo.user_id

Related


Select raw data value using JS/jquery

Well I am trying to select values from some raw data using jquery. I have tried something like this The var id = $("body").data("id"); original data looks like this {"photo":{"id":85456501,"user_id":601182}} Any ideas? Mathias You can get the raw data string i

Reorganize key/value data using the Select statement

South Claw Hare I have some effectively organized tables like in this example: Broadly speaking, there are many "assets" that contain names and values in the form of "tags", which contain a many-to-many list of key/value pairs. Each asset can have any subset o

Reorganize key/value data using the Select statement

South Claw Hare I have some effectively organized tables like in this example: Broadly speaking, there are many "assets" that contain a many-to-many list of "key/value" pairs of names and values in the form of "tags". Each asset can have any subset of tags, an

Reorganize key/value data using the Select statement

South Claw Hare I have some effectively organized tables like in this example: Broadly speaking, there are many "assets" that contain names and values in the form of "tags", which contain a many-to-many list of key/value pairs. Each asset can have any subset o

SELECT(MAX) SQL to Eloquent without raw data

Nathan Meyer I'm migrating my scripts using Eloquent instead of my company's SQL. I want to do this simple query with Eloquent, but I don't know how to do it. SQL query: SELECT MAX(date), id FROM myTable WHERE people > 0 GROUP BY id +-------------------------

get data from "raw select for xml"

Alexander ZInchenko I have a query with a selection of raw statements in xml. the result looks like <row link="someLink" DATASOURCE="SomeSystem" obj_id="1" err_id="1" /> <row link="someLink" DATASOURCE="SomeSystem" obj_id="1" err_id="2" /> or <row UWI="123" X

get data from "raw select for xml"

Alexander ZInchenko I have a query with a selection of raw statements in xml. the result looks like <row link="someLink" DATASOURCE="SomeSystem" obj_id="1" err_id="1" /> <row link="someLink" DATASOURCE="SomeSystem" obj_id="1" err_id="2" /> or <row UWI="123" X

Small ticket localization value in data raw header

falcon Is it possible to use wicket:message to put a value from a properties file into the tag parameter without using Java. For example I have the following elements<i class="ico ico-filter-code" data-toggle="tooltip" data-placement="top" title="" data-origin

HTML select check data value from JSON using Javascript

TGB I have html select value and input value, so if I can select value, I need to extract the value of the data from JSON and then return the value to the input value Please check the following code <select name="bundle_typeCode" id="bundle_typeCode" class="fo

HTML select check data value from JSON using Javascript

TGB I have html select value and input value, so if I can select value, I need to extract the value of the data from JSON and then return the value to the input value Please check the following code <select name="bundle_typeCode" id="bundle_typeCode" class="fo

HTML select check data value from JSON using Javascript

TGB I have html select value and input value, so if I can select value, I need to extract the value of the data from JSON and then return the value to the input value Please check the following code <select name="bundle_typeCode" id="bundle_typeCode" class="fo