Avatar of karthik80c
karthik80c
Flag for United States of America asked on

How to count json data

Hi Experts,


I want to count the json data in it and i tried with
var propertyData = JSON.parse(rsp);
var length =  Object.keys(propertyData).length;

Open in new window

. but my json lenght is 1 . Instead function returning me the 6 which is each property of json . how can i get rid of it

My Json
"{\r\n  \"FullImage\": \"http://localhost:57226/img/image1.JPG\",\r\n  \"imageThumb\": \"http://localhost
:57226/img/image1.JPG\",\r\n  \"description\": \"Kitchen\",\r\n  \"Address\": \"Test\",\r\n  \"imageid
\": 1,\r\n  \"TextColor\": \"White\"\r\n}"

Open in new window


Thanks Experts
ASP.NETJSONjQueryC#Scripting Languages

Avatar of undefined
Last Comment
ste5an

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
YZlat

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ste5an

The question is how you handle the JSON and the real content of rsp..

Counting is simple:

<!DOCTYPE html>
<html>
<body>
	<script type="text/javascript" src="jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			var data = 		
			{  
				"FullImage": "http://localhost:57226/img/image1.JPG",  
				"imageThumb": "http://localhost:57226/img/image1.JPG", 
				"description": "Kitchen",  
				"Address": "Test",
				"imageid": 1, 
				"TextColor": "White"
			};
			var json = JSON.stringify(data);
			var fromJson = JSON.parse(json);
			var length =  Object.keys(fromJson).length;
			$("#result").text(length);
		});
	</script>
	<div id="result">..</div>
</body>
</html>

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck