474,046 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with my JSON string???

Hi.

I can't seem to get any values from the below string.
I have tried myJSONObject.sl ides[0], myJSONObject.sl ides['1'],
myJSONObject.sl ides[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 1558
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.sl ides[0], myJSONObject.sl ides['1'],
myJSONObject.sl ides[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.sl ides[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.respons eText;
var myJSONObject = eval("(" + x + ")");

I get "(" expected.

When I try

var x = xmlhttp.respons eText;
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.respons eText;
var myJSONObject = eval("(" + x + ")");

I get "(" expected.

When I try

var x = xmlhttp.respons eText;
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.s lides[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
6924
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... PS i am ready to use JSON as data/object interchange when using AJAX and my J2EE project - because it is easier to traverse the JavaScript object than its XML representation (so of course may argue).
2
3781
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 considered bad practice because it can disrupt the use of for in loops on Objects. Am I incorrect? Thanks,
1
1745
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 JSON extension that allows cross-references, and I'm asking for your thoughts on a simple type system. I've dubbed this variation RJSON (Red's JSON) for lack of a shorter name. Here's how it works right now:
3
18149
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 tries to eval() it: var jsonStr = eval('(' + str + ')');
2
1725
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
2318
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 would like to read the JSON string sent from the client on the
4
8892
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 org.json.JSONException;
7
3060
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 . Putting the JSON into a foreach loop DOES access the member: foreach($json as $key=>$value) {
6
2850
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
6721
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 import="java.util.Map;" %> <%@ page import="com.google.gson.Gson;" %>
0
10548
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11604
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12027
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5420
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3973
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.