2015년 11월 27일 금요일

jQuery에서 문자열을 json 객체로 변환시...


parseJSON 을 사용하면 되는 건 맞는데!!! 주의 할 점!!!

문서 대강대강 보다가.. 2시간 날림..!!

문자열 만들때..


1
2
var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );

반드시!!! 쌍따옴표를 써야 한다.. javascript여서.. 홑따옴표로 변형해서 썼더니 절대 안됐음..

설명을 잘 읽어 볼걸......

Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all invalid JSON strings:
  • "{test: 1}" (test does not have double quotes around it).
  • "{'test': 1}" ('test' is using single quotes instead of double quotes).
  • "'test'" ('test' is using single quotes instead of double quotes).
  • ".1" (a number must start with a digit; "0.1" would be valid).
  • "undefined" (undefined cannot be represented in a JSON string; null, however, can be).
  • "NaN" (NaN cannot be represented in a JSON string; direct representation of Infinity is also not permitted).

댓글 없음:

댓글 쓰기

[DOS] ULTIMA 2 클리어

  몰아쓰는 거라.. 포스팅을 또 함.. ​ 울티마를 하려면.. 일단 메뉴얼부터 정독을 하고 뭘해야 할 지를 정한다음 게임을 해야 한다.. ​ 2편 메뉴얼을 보니.. 형편없는 쓰레기게임이구나.. 라는 생각만 든다.. ​ 낭만의 시대적 게임이라.. 정말...