В дополнение к другим ответам, я рекомендую эту онлайн-службу open source jsonschema2pojo.org для быстрого генерации Java-классов из json или json-схемы для GSON, Jackson 1.x или Jackson 2.x. Например, если у вас есть:
{
"pageInfo": {
"pageName": "abc",
"pagePic": "http://example.com/content.jpg"
}
"posts": [
{
"post_id": "123456789012_123456789012",
"actor_id": 1234567890,
"picOfPersonWhoPosted": "http://example.com/photo.jpg",
"nameOfPersonWhoPosted": "Jane Doe",
"message": "Sounds cool. Can't wait to see it!",
"likesCount": 2,
"comments": [],
"timeOfPost": 1234567890
}
]
}
jsonschema2pojo.org для генерируемого GSON:
@Generated("org.jsonschema2pojo")
public class Container {
@SerializedName("pageInfo")
@Expose
public PageInfo pageInfo;
@SerializedName("posts")
@Expose
public List posts = new ArrayList();
}
@Generated("org.jsonschema2pojo")
public class PageInfo {
@SerializedName("pageName")
@Expose
public String pageName;
@SerializedName("pagePic")
@Expose
public String pagePic;
}
@Generated("org.jsonschema2pojo")
public class Post {
@SerializedName("post_id")
@Expose
public String postId;
@SerializedName("actor_id")
@Expose
public long actorId;
@SerializedName("picOfPersonWhoPosted")
@Expose
public String picOfPersonWhoPosted;
@SerializedName("nameOfPersonWhoPosted")
@Expose
public String nameOfPersonWhoPosted;
@SerializedName("message")
@Expose
public String message;
@SerializedName("likesCount")
@Expose
public long likesCount;
@SerializedName("comments")
@Expose
public List
попробуйте
function namedFunction(){
alert("Hello world!")
}
$("#clickTester").on('click', namedFunction)
Вам не нужен ()
для вашей функции здесь:
$("#selector").on("click", namedFunction)
Function namedFunction () {
alert("Hello world!");
}
$("#clickTester").on('click', namedFunction);
$("#clickTester").click(function(){
alert("Hello world!");
});
Просто передайте reference
самой функции.
Попробуйте
$("#selector").on("click", namedFunction);