473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What is wrong with my JSON string???

Hi.

I can't seem to get any values from the below string.
I have tried myJSONObject.slides[0], myJSONObject.slides['1'],
myJSONObject.slides[0].1, etc.
I can't get it to work. Is it because the NAMES are numbers? Can you
get this to work?

Thanks.

"{'slides': [{'2': 's002.jpg', '3': 's003.jpg', '4': 's004.jpg', '5':
's005.jpg', '6': 's006.jpg', '7': 's007.jpg', '48': 's048.jpg', '17':
's017.jpg', '27': 's027.jpg', '37': 's037.jpg', '15': 's015.jpg',
'25': 's025.jpg', '35': 's035.jpg', '13': 's013.jpg', '23':
's023.jpg', '33': 's033.jpg', '11': 's011.jpg', '21': 's021.jpg',
'31': 's031.jpg', '41': 's041.jpg', '47': 's047.jpg', '57':
's057.jpg', '19': 's019.jpg', '29': 's029.jpg', '39': 's039.jpg',
'46': 's046.jpg', '56': 's056.jpg', '49': 's049.jpg', '51':
's051.jpg', '42': 's042.jpg', '52': 's052.jpg', '45': 's045.jpg',
'55': 's055.jpg', '16': 's016.jpg', '26': 's026.jpg', '36':
's036.jpg', '14': 's014.jpg', '24': 's024.jpg', '34': 's034.jpg',
'12': 's012.jpg', '22': 's022.jpg', '32': 's032.jpg', '10':
's010.jpg', '20': 's020.jpg', '30': 's030.jpg', '40': 's040.jpg',
'50': 's050.jpg', '44': 's044.jpg', '54': 's054.jpg', '18':
's018.jpg', '28': 's028.jpg', '38': 's038.jpg', '8': 's008.jpg', '9':
's009.jpg', '43': 's043.jpg', '53': 's053.jpg', '1': 's001.jpg'}]};"
Feb 6 '08 #1
6 1534
On Feb 6, 1:41 pm, pbd22 <dush...@gmail.comwrote:
Hi.

I can't seem to get any values from the below string.
I have tried myJSONObject.slides[0], myJSONObject.slides['1'],
myJSONObject.slides[0].1, etc.
I can't get it to work. Is it because the NAMES are numbers? Can you
get this to work?

Thanks.

"{'slides': [{'2': 's002.jpg', '3': 's003.jpg', '4': 's004.jpg', '5':
's005.jpg', '6': 's006.jpg', '7': 's007.jpg', '48': 's048.jpg', '17':
's017.jpg', '27': 's027.jpg', '37': 's037.jpg', '15': 's015.jpg',
'25': 's025.jpg', '35': 's035.jpg', '13': 's013.jpg', '23':
's023.jpg', '33': 's033.jpg', '11': 's011.jpg', '21': 's021.jpg',
'31': 's031.jpg', '41': 's041.jpg', '47': 's047.jpg', '57':
's057.jpg', '19': 's019.jpg', '29': 's029.jpg', '39': 's039.jpg',
'46': 's046.jpg', '56': 's056.jpg', '49': 's049.jpg', '51':
's051.jpg', '42': 's042.jpg', '52': 's052.jpg', '45': 's045.jpg',
'55': 's055.jpg', '16': 's016.jpg', '26': 's026.jpg', '36':
's036.jpg', '14': 's014.jpg', '24': 's024.jpg', '34': 's034.jpg',
'12': 's012.jpg', '22': 's022.jpg', '32': 's032.jpg', '10':
's010.jpg', '20': 's020.jpg', '30': 's030.jpg', '40': 's040.jpg',
'50': 's050.jpg', '44': 's044.jpg', '54': 's054.jpg', '18':
's018.jpg', '28': 's028.jpg', '38': 's038.jpg', '8': 's008.jpg', '9':
's009.jpg', '43': 's043.jpg', '53': 's053.jpg', '1': 's001.jpg'}]};"
Did you try myJSONObject.slides[0]['2']?
Feb 6 '08 #2
yes, thanks.

I get slides.0 is null or not an object.

should I be using eval?

when I try

var x = xmlhttp.responseText;
var myJSONObject = eval("(" + x + ")");

I get "(" expected.

When I try

var x = xmlhttp.responseText;
var myJSONObject = eval(x);

I get ";" expected;

I am lost. Why I am I getting these errors?
try/catch isn't really helping. Would somebody
mind throwing my string in their compiler to see
if you get different results?

thanks.

Feb 6 '08 #3
On Feb 6, 1:41*pm, pbd22 <dush...@gmail.comwrote:
<snip>
"{'slides': [{'2': 's002.jpg', '3': 's003.jpg', '4': 's004.jpg', '5':
<snip>
's009.jpg', '43': 's043.jpg', '53': 's053.jpg', '1': 's001.jpg'}]};"
^

That semicolon at the end of your "JSON" string is erroneous.

Feb 6 '08 #4
On Feb 6, 3:35 pm, pbd22 <dush...@gmail.comwrote:
yes, thanks.

I get slides.0 is null or not an object.

should I be using eval?

when I try

var x = xmlhttp.responseText;
var myJSONObject = eval("(" + x + ")");

I get "(" expected.

When I try

var x = xmlhttp.responseText;
var myJSONObject = eval(x);

I get ";" expected;

I am lost. Why I am I getting these errors?
try/catch isn't really helping. Would somebody
mind throwing my string in their compiler to see
if you get different results?

thanks.
I tried it this way (NOT using JSON, just plain javascript)

function setVars(){
thisVal = {'slides': [{'2': 's002.jpg', '3': 's003.jpg', '4':
's004.jpg', '5':'s005.jpg', '6': 's006.jpg', '7': 's007.jpg', '48':
's048.jpg', '17':'s017.jpg', '27': 's027.jpg', '37': 's037.jpg', '15':
's015.jpg','25': 's025.jpg', '35': 's035.jpg', '13': 's013.jpg',
'23':'s023.jpg', '33': 's033.jpg', '11': 's011.jpg', '21':
's021.jpg','31': 's031.jpg', '41': 's041.jpg', '47': 's047.jpg',
'57':'s057.jpg', '19': 's019.jpg', '29': 's029.jpg', '39':
's039.jpg','46': 's046.jpg', '56': 's056.jpg', '49': 's049.jpg',
'51':'s051.jpg', '42': 's042.jpg', '52': 's052.jpg', '45':
's045.jpg','55': 's055.jpg', '16': 's016.jpg', '26': 's026.jpg',
'36':'s036.jpg', '14': 's014.jpg', '24': 's024.jpg', '34':
's034.jpg','12': 's012.jpg', '22': 's022.jpg', '32': 's032.jpg',
'10':'s010.jpg', '20': 's020.jpg', '30': 's030.jpg', '40':
's040.jpg','50': 's050.jpg', '44': 's044.jpg', '54': 's054.jpg',
'18':'s018.jpg', '28': 's028.jpg', '38': 's038.jpg', '8': 's008.jpg',
'9':'s009.jpg', '43': 's043.jpg', '53': 's053.jpg', '1':
's001.jpg'}]};
}
function getVars(){
alert(thisVal.slides[0]['2']);
}

and it worked...
What was your problem?
Feb 6 '08 #5
Thanks both.

Henry was right, the semicoln shouldn't have been there.

Thanks again.
Peter
Feb 7 '08 #6
pbd22 wrote:
Thanks both.

Henry was right, the semicoln shouldn't have been there.
JSLint can find these sorts of problems in JSON text.

http://www.JSLint.com/
Feb 8 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
2
by: Kevin Newman | last post by:
Hello, I noticed that the JavaScript library for JSON posted on json.org (http://www.json.org/json.js) is modifying Object.prototype (adding a method - toJSONString). I thought this was...
1
by: Red Daly | last post by:
Hello group, I have been using JSON for a while and it has made many things a breeze. However, JSON does not natively describe certain things like pointers and custom types. I created a simple...
3
by: asleepatdesk | last post by:
Hi, I need some help here. When I try to eval() my AJAX returned JSON string, I continually get a javascript error "Expected )". Here's my JSON string: {"recs": }; My js function simply...
2
by: eggie5 | last post by:
Is this JSON valid? I would like to access it like this in my javascript: var json=eval ('('+json+')'); json.devices.modelNumber and json.devices.image Would this work?
1
by: seth | last post by:
Hi: I'm trying to read JSON strings sent from the browser. Here is the scenario: 1. Using YUI tookit 2. sending JSON string from YUI toolkit - using the provided asyncRequest method. **I...
4
by: im12345 | last post by:
I have the following question: Im doing a sample application using dojo and json. I have 2 classes: 1. Book class package com.esolaria.dojoex; import org.json.JSONObject; import...
7
by: Logos | last post by:
I am using PHP with the JSON extension function json_decode. I have a JSON with a member named "1" (ie) { "1":"somedata" } Trying to access this via the -operator doesn't work, nor does . ...
6
by: Lasse Reichstein Nielsen | last post by:
Max <adsl@tiscali.itwrites: Not really. It shows that a particularly naïve implementation of a conversion from XML to JSON doesn't work well. What if the conversion of <e> some
5
by: najmi | last post by:
hai.. i hava use FullCalendar in my application.i try to reload event into the calendar but it doesn`t work.here is my code <%@ page import="java.util.HashMap;" %> <%@ page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.