【php和json的相互转换】教程文章相关的互联网学习教程文章

c# – 反序列化json对象并将内部对象转换为字符串值?【代码】

我有一个webservice返回json数据.我无法控制服务器端生成的json. 我像这样反序列化json:JsonConvert.DeserializeObject<OuterObject>(jsonString);问题是嵌入了内部对象(有很多嵌套的内部对象).我没兴趣在我的应用程序中对它们进行建模. json数据是这样的:{ id : "xyz",name : "Some Object",properties : {prop_1 : "foo",prop_2 : "bar"},inner_object : {id : "abc$1",name : "Inner Object Name",....// a whole lot of stuf...

javascript – 如何防止jQuery的$.getJSON将我的ajax响应键从字符串转换为整数?【代码】

我正在尝试使用通过电子邮件排序的JSON响应对象来填充选择框,但JQuery似乎正在将键的类型从文本更改为整数,因此通过现在的数字索引重新排序响应对象,搞砸了选择框的顺序. 所以json的反应如下:{"2":"aaron@mail.com","1":"bernard@mail.com"}在代码类似于:$.getJSON('urlwithjsonresponse.com',function(response){console.log(response); });输出这样的对象:{1:"bernard@mail.com",2:"aaron@mail.com"}如何防止此转换/重新排序?...

【Python】python 中 json、class、str 的相互转换

参考: https://blog.csdn.net/qq_29201493/article/details/85697377#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @File : garbage_test.py @Time : 2019/06/15 08:26:17 @Author : California Fruit @Desc : None '''import json class Student(object):def __init__(self, name, age, score,reward):self.name = nameself.age = ageself.score = scoreself.reward = rewarddef json_2str():data_js...

使用PHP解码Microsoft转换器API的JSON输出【代码】

这个问题似乎特定于microsofttranslator.com所以请…任何答案,如果你可以测试它… 使用以下URL进行翻译:http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray ..我通过cURL发送了一些很棒的参数,并得到以下结果:[{"From":"en","OriginalTextSentenceLengths":[13],"TranslatedText":"我是最好的","TranslatedTextSentenceLengths":[5]},{"From":"en","OriginalTextSentenceLengths":[16],"TranslatedText":"你是最好的...

json在php中的使用之如何转换json为数组【代码】

<?php$json = {"a":1,"b":2,"c":3,"d":4,"e":5};var_dump(json_decode($json));echo"<br/>";var_dump(json_decode($json, true)); ?>数组$json = {"a":1,"b":2,"c":3,"d":4,"e":5};被json_decode()解码,转换回来的数据是对象,var_dump(json_decode($json))得到的是一个对象,如下:1object(stdClass)#1 (5) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["d"]=> int(4) ["e"]=> int(5) }那么,要怎么样才能把json数组转换为p...

将复杂的json转换为c#类【代码】

我一直在尝试使用来自此网站和其他网站的类似问题的帮助,将以下json数据反序列化为2天,并且可能会使脑死亡. 我有这个json数据(长度道歉)并且我正在尝试,作为开始在’Values’数组中获得’value’数字: – {"metadata": {"columnGrouping": ["area","metricType","period","valueType"],"rowGrouping": []},"columns": [{"area": {"identifier": "E31000040","label": "Gtr Manchester Fire","altLabel": "Gtr Manchester Fire","i...

javascript – 如何在不丢失TypeScript类属性的情况下将JSON对象列表转换为TypeScript对象列表?【代码】

我有这个Customer类:export class Customer {id: number;company: string;firstName: string;lastName: string;name(): string {if (this.company)return this.company;if (this.lastName && this.firstName)return this.lastName + ", " + this.firstName;if (this.lastName)return this.lastName;if (this.firstName)return this.firstName;if (this.id > 0)return "#" + this.id;return "New Customer";} }在我的控制器中,我下...

javascript – 给定一个json对象数组,如何将每个对象中的值转换为int或float?【代码】

给定一个json对象数组,如何将每个对象中的值转换为int或float?var data = [{"rank": "1","name": "Bill"},{"rank": "2","name": "Ted"},{"rank": "3","name": "John"},{"rank": "4","name": "Jane"} ]我正在使用的json对象在两个维度上都要大得多,所以我试图找出如何使用map函数将“rank”部分从字符串转换为int.还有其他部分我想转换为浮点数,但现在按“排名”排序1,10,11,12等. 我怎样才能做到这一点?我正在使用React / ES6 / ...

在python中将分隔的字符串转换为分层JSON【代码】

如何在python中将分隔的字符串转换为分层JSON.我在jQuery中看到了类似问题的解决方案.我一直试图找到相同的python解决方案. Convert delimited string into hierarchical JSON with JQuery 目标是从一堆URL中生成类别的分层json,这些URL可能如下所示运动/网球/ grandslams体育/棋体育/棋/播放/人体育/网球运动/板球/体育场馆运动/网球/播放器解决方法:你可以用词典实现这个目的:initial = ["Fred-Jim","Fred","Fred-Jim-Bob", "Fr...

java – 将具有多个功能的Kml转换为Geojson【代码】

我使用此代码将具有单个功能的kml文件转换为GeoJson文件.String kmlToGeoJson(String fileName)throws IOException, ParserConfigurationException, SAXException, XMLStreamException {FileInputStream reader = new FileInputStream(fileName);PullParser parser = new PullParser(new KMLConfiguration(),reader, SimpleFeature.class);FeatureJSON fjson = new FeatureJSON();FileWriter tmp = new FileWriter(fileName + ".ge...

java – 如何读取json文件,并使用GSON将其转换为POJO【代码】

我需要将值从json文件传递到java类,json文件就像这样的例子:{"id":1,"name":"Gold","description":"Shiny!","spriteId":1,"consumable":true,"effectsId":[1]},我需要映射,我做了这个:Items i = new Items();Map<String, Items> mapaNomes = new HashMap<String, Items>(); mapaNomes.put("Gold",i); mapaNomes.put("Apple",i ); mapaNomes.put("Clain Mail",i );我是Android开发人员的新手,我可能会忘记一些事情因为以下内容不起...

c# – Automapper:将JSON转换为对象列表【代码】

源对象(JSON,如果重要的话,使用JSON.NET):{"conum" : 1001,"name" : "CLN Industries Corporation","agencyName" : "Murphy, Holmes & Associates, LLC","sAA" : [{"code" : 247,"description" : "Mechanic\u0027s lien - Bond to Discharge - Fixed penalty - where principal has posted Performance and Pa"}, {"code" : 277,"description" : "Mechanic\u0027s lien - Bond to Discharge - Open Penalty - where principal has...

如何使用java rdf4j将RDF转换为漂亮的嵌套JSON【代码】

我有一个简单的RDF文件,并希望将其转换为漂亮的嵌套JSON.:b0 a <http://schema.org/Book> ;<http://schema.org/name> "Semantic Web Primer (First Edition)" ;<http://schema.org/offers> _:b1 ;<http://schema.org/publisher> "Linked Data Tools" ._:b1 a <http://schema.org/Offer> ;<http://schema.org/price> "2.95" ;<http://schema.org/priceCurrency> "USD" .应该成为{"type" : "Book","name" : "Semantic Web Primer (Fi...

javascript – 在ReactJS应用程序中将字符串转换为JSON对象时出错【代码】

作为我不断努力学习ReactJS的一部分,我正在开发一个简单的页面,它将呈现如下趋势列表:单击“获取趋势”按钮后,将通过websockets从后端服务器检索趋势列表并显示.它按预期工作.以下是相应的源代码:import React, { Component } from 'react'; import './App.css';class TrendRow extends Component {render() {return (<tr><td>{this.props.onerow}</td></tr>);} }class TrendTable extends Component {render() {var rows = [];f...

将JSON字符串转换/映射到javabean的最简单方法是什么?【代码】

我有一个JSON字符串,我读入并想要解析/映射到JavaBean,所以我可以在我的Java代码中使用它.实现这一目标的最简单方法/库是什么?解决方法:我写了一个JSON库来做到这一点.. http://code.google.com/p/svenson/ 使用svenson你会做类似的事情:// assume json to be a JSON dataset as String MyBean bean = JSONParser.defaultJSONParser().parse(MyBean.class, json);Svenson允许您自由选择使用地图/列表或您自己的POJO来转换JSON数据...