我试图读取一个JSON文件并解析它.我有这个代码从我的文件中读取
StreamReader re = new StreamReader("artists.json");
JsonTextReader reader = new JsonTextReader(re);
Run Code Online (Sandbox Code Playgroud)
但是我现在如何从读者解析它以便我可以从文件中搜索数据?
我试过阅读文档但找不到任何东西
我试图解析JSON文件并插入到SQL DB中.只要文件很小(小于5 MB),我的解析器工作得非常好.
我在尝试读取大(> 5MB)文件时遇到"Out of memory exception".
if (System.IO.Directory.Exists(jsonFilePath))
{
string[] files = System.IO.Directory.GetFiles(jsonFilePath);
foreach (string s in files)
{
var jsonString = File.ReadAllText(s);
fileName = System.IO.Path.GetFileName(s);
ParseJSON(jsonString, fileName);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了JSONReader方法,但没有运气将整个JSON转换为字符串或变量.请指教.
我正在尝试使用下面的代码解析我的 json。我收到错误:
从 JsonReader 读取 JObject 时出错。路径 '',第 0 行,位置 0。
我想这可能是因为我的 JSON 格式错误,所以我输出了它,看起来没问题:
{
"serviceDeskId": "4",
"requestTypeId": "223",
"requestFieldValues": {
"summary": "test"
}
}
Run Code Online (Sandbox Code Playgroud)
但现在我完全陷入困境了。谁能看到我哪里出错了?这真让我抓狂!!
正是在这一行触发了错误:
var jsonresponse = JObject.Parse(response);
Run Code Online (Sandbox Code Playgroud)
完整代码片段:
req.ContentType = "application/json";
var json = JObject.Parse(
"{\"serviceDeskId\": \"4\",\"requestTypeId\": \"223\",\"requestFieldValues\": {\"summary\": \"" +
summary.Value + "\"}}");
jsonCheck = json.ToString();
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
streamWriter.Write(json);
}
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = resp.GetResponseStream(); …
Run Code Online (Sandbox Code Playgroud) 在Ext.data的上下文中,JsonStore和JsonReader之间的基本区别是什么?
我的意思是什么时候我应该去JsonStore,当我应该使用JsonReader时,我都提供相同的解决方案.
我正在尝试使用C#和JSON.Net在网站上加载JSON文件
但是,我在运行时遇到问题,因为所有JSON都在[]内.
这是JSON:
[{"embed_count":"16","name":"live_user_catreina","stream_count":"133","category":"gaming","format":"live","channel_count":272,"title":"SWTOR - Sith Marauder - L42 - Belsavis - The Fatman","featured":true,"site_count":"117","abuse_reported":false,"channel":{"image_url_large":"http://static-cdn.jtvnw.net/jtv_user_pictures/catreina-profile_image-2c63d1c5b60987da-300x300.jpeg","channel_url":"http://www.justin.tv/catreina","category_title":"Gaming","screen_cap_url_large":"http://static-cdn.jtvnw.net/previews/live_user_catreina-320x240.jpg","mature":null,"subcategory":null,"category":"gaming","image_url_medium":"http://static-cdn.jtvnw.net/jtv_user_pictures/catreina-profile_image-2c63d1c5b60987da-150x150.jpeg","subcategory_title":null,"status":"SWTOR - Sith Marauder - L42 - Belsavis - The Fatman","screen_cap_url_medium":"http://static-cdn.jtvnw.net/previews/live_user_catreina-150x113.jpg","image_url_small":"http://static-cdn.jtvnw.net/jtv_user_pictures/catreina-profile_image-2c63d1c5b60987da-70x70.jpeg","timezone":"US/Eastern","screen_cap_url_small":"http://static-cdn.jtvnw.net/previews/live_user_catreina-70x53.jpg","id":5895485,"views_count":"6142420","embed_enabled":true,"embed_code":" <object type=\"application/x-shockwave-flash\" height=\"295\" width=\"353\" id=\"live_embed_player_flash\" data=\"http://www.justin.tv/widgets/live_embed_player.swf?channel=catreina\" bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://www.justin.tv/widgets/live_embed_player.swf\" /><param name=\"flashvars\" value=\"start_volume=25&channel=catreina&auto_play=false\" /></object>\n","producer":true,"image_url_tiny":"http://static-cdn.jtvnw.net/jtv_user_pictures/catreina-profile_image-2c63d1c5b60987da-50x50.jpeg","image_url_huge":"http://static-cdn.jtvnw.net/jtv_user_pictures/catreina-profile_image-2c63d1c5b60987da-600x600.jpeg","language":"en","tags":"games gaming lord lotro mmo mmorpg of online pc rings rpg sc2 scii starcraft starcraft2 the vindictus warcraft wow","login":"catreina","screen_cap_url_huge":"http://static-cdn.jtvnw.net/previews/live_user_catreina-630x473.jpg","title":"Gaming With Catreina"},"video_height":720,"language":"en","video_bitrate":1987.1328125,"id":"2309110144","meta_game":"Star Wars: The Old Republic","broadcaster":"fme","broadcast_part":4,"audio_codec":"uncompressed","up_time":"Mon Dec 26 00:06:03 2011","video_width":1280,"geo":"US","channel_view_count":6133751,"channel_subscription":false,"embed_enabled":true,"stream_type":"live","video_codec":"AVC"}]
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码加载它:
class Program
{
static void Main(string[] args)
{ …
Run Code Online (Sandbox Code Playgroud) 在Java中使用GSON是否有任何注释,我可以指示一个字段,即使它是一个对象,它应该将它保持为原始字符串.?
或者最简单的方法是什么?
//This is the original
@SerializedName("perro")
public Perro perro
//This is what I want to achieve
@SerializedName("perro")
public String perro
So the result should be
perro = "{"Users":[{"Name":"firulais","Raza":"beagle"},{"Name":"Spike","Value":"Terrier"}]}"
Run Code Online (Sandbox Code Playgroud) 我正在使用JsonReader从网站获取大量数据并保存到数据库.顺便提一下,每当读者没有找到对象项的值时,它就会失败并停止执行.
这是我的错误;
System.err? java.lang.IllegalStateException: Expected a string but was NULL at line 1 column 359337 path $[19].date
Run Code Online (Sandbox Code Playgroud)
即使指定的值不可用,似乎在遇到错误之前加载的所有对象也会丢失,并且不会保存到db.有没有办法处理这些错误并保留到目前为止已加载的对象?我已将JsonReader设置为lenient.
这是解析数据的方法的一部分:
private Post read(JsonReader reader) throws Exception {
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
switch (name) {
case TITLE:
mTitle = new StringBuilder();
mTitle.append(reader.nextString());
break;
case AUTHOR:
if (reader.hasNext()) {
JsonToken peek = reader.peek();
if (peek == JsonToken.NULL) {
reader.skipValue();
} else {
reader.beginObject();
while (reader.hasNext()) {
String enclosedName = reader.nextName();
switch (enclosedName) {
case NAME:
mAuthor = new StringBuilder(); …
Run Code Online (Sandbox Code Playgroud) 我正在玩JsonReader
Android中的流式JSON解析器,我遇到了一个问题,即解析器不会遍历json数组中的所有项目,它只会返回第一个项目.
这是我用来解析的代码:
private ArrayList<Result> readResultsArray(JsonReader reader) throws IOException {
ArrayList<Result> results = new ArrayList<Result>();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("results")){
reader.beginArray();
while (reader.hasNext()) {
results.add(readResult(reader));
}
reader.endArray();
} else {
reader.skipValue();
}
}
reader.endObject();
return results;
}
Run Code Online (Sandbox Code Playgroud)
我确信该方法readResult(reader)
将解析并返回数组中的第一个对象而没有任何问题.
但读者似乎只是"忽略"了数组中的第二个对象.
这是readResult(reader)
方法:
private Result readResult(JsonReader reader) throws IOException {
String from_user = null,
from_user_id_str = null,
from_user_name = null,
text = null;
Geo geo = null;
URL profile_image_url = null;
reader.beginObject();
while …
Run Code Online (Sandbox Code Playgroud) 在我的ExtJS应用程序中,我使用EditorGridPanel来显示来自服务器的数据.
var applicationsGrid = new Ext.grid.EditorGridPanel({
region: 'west',
layout: 'fit',
title: '<img src="../../Content/img/app.png" /> ??????????',
collapsible: true,
margins: '0 0 5 5',
split: true,
width: '30%',
listeners: { 'viewready': { fn: function() { applicationsGridStatusBar.setText('??????????: ' + applicationsStore.getTotalCount()); } } },
store: applicationsStore,
loadMask: { msg: '????????...' },
sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: { 'rowselect': { fn: applicationsGrid_onRowSelect} }
}),
viewConfig: { forceFit: true },
tbar: [{
icon: '../../Content/img/add.gif',
text: '????????'
}, '-', {
icon: '../../Content/img/delete.gif',
text: '???????'
}, '-'], …
Run Code Online (Sandbox Code Playgroud)